Cyclic barrier synchronization rounds

Write codeMedium25 minMicrosoft style

Your task

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.

Examples

barrier_rounds(n: int, arrivals: list[int]) -> list[int]
Example 1
Inputbarrier_rounds(3, [0, 1, 2, 0, 1])
Output[1, 2]