Code RoomCyclic barrier synchronization rounds
MediumPrep Room Coding #174

Cyclic barrier synchronization rounds

CodingConcurrencyMid–Senior~25 min

N threads repeatedly synchronize at a cyclic barrier of party size N: a barrier 'trips' (releases) exactly when N threads have called arrive() since the last trip, and the counter then resets for the next round. You are given a list `arrivals` of thread ids in the order they call arrive(). Each arrival increments the count; every time the count reaches N the barrier trips (count a completed round) and resets to 0. Return a pair [rounds, waiting] where rounds is the number of completed barrier trips and waiting is the number of threads currently blocked at the barrier (arrived but not yet released) at the end.

Implement
barrier_rounds(n: int, arrivals: list[int]) → list[int]
Examples
in[3,[0,1,2,0,1]]out[1,2]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[3,[0,1,2,0,1]][1,2]not run yetsample