FastPrepReusable Cyclic Barrier
Problems/Reusable Cyclic Barrier

Reusable Cyclic Barrier

Apple logoApple● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Apple full-time phone screen. The report asks for a low-level cyclic barrier. Our version keeps the waiting, the release of everyone together, and reuse, shown as a finite trace of atomic arrivals. We chose the number of parties, who may take part, how rounds are numbered, and how the final answer is written. We did not keep real thread scheduling or broken, reset, and timeout behavior.

A cyclic barrier makes participants wait until a full group has arrived, then lets the whole group go at once. It can then be reused for the next group. Simulate this for a list of arrivals, processed in order.

The barrier works in rounds called generations, numbered from generation 0. parties is the group size, and it is always positive. Each entry in participantIds is one participant arriving at the barrier and waiting there, as a single step. When exactly parties participants have arrived in the current generation, all of them are released together, and the next generation begins.

A participant who is still waiting cannot arrive again. Once released, the same participant may arrive again right away, in a later generation. The input always follows this rule. A generation does not have to use the same participants as the one before it.

After all arrivals are processed, return one string per arrival, in order. Write RELEASE g if that arrival's generation g was completed. Write WAIT g if it belongs to the last generation and that generation is still not full. Write each generation number as a plain decimal integer, starting at 0. The barrier never breaks, resets, cancels or times out.

Function

runCyclicBarrier(parties: int, participantIds: int[]) → String[]

Examples

Example 1

parties = 2participantIds = [1,2,1]return = ["RELEASE 0","RELEASE 0","WAIT 1"]

The first two arrivals fill the first generation and are released together. The first participant then arrives again, which is allowed after a release. It waits alone in generation 1, which never fills, so its result is a wait.

Example 2

parties = 3participantIds = [8,9]return = ["WAIT 0","WAIT 0"]

Only two participants arrive, but a full group needs three. The first generation never fills, so both arrivals end up waiting.

Example 3

parties = 1participantIds = [7,7]return = ["RELEASE 0","RELEASE 1"]

With a group size of one, every arrival fills its generation by itself. The participant is released in the first generation, then arrives again and is released in the second one.

Constraints

  • 1 <= parties <= 1000.
  • 0 <= participantIds.length <= 2000.
  • Participant IDs are integers in [0,10^9].
  • No participant repeats within an incomplete generation.

More Apple Phone Screen questions

  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
  • Evaluate DivisionPHONE SCREEN · Seen Nov 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
  • Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
  • Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
  • Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
  • Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • LRU CacheAthenahealth · PHONE SCREEN
  • Rate Limiter with a Sliding Window per ClientStackAdapt · PHONE SCREENStackAdapt interview questions
  • Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
  • Timed Cache with Sidecar CleanupNetflix · PHONE SCREEN · ONSITE INTERVIEWNetflix interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Mutable Points in a Hash Set and a ListMillennium · PHONE SCREENMillennium interview questions
  • Rolling Hit CounterDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple India SWE New Grad Interviews: 5 Experiences
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public String[] runCyclicBarrier(int parties, int[] participantIds) {
        // Write your code here.
    }

}
Checking account…