Code Room
CodingMediumcod-g1137
Subject ConcurrencyLevel Mid–Senior~30 minCommon in Concurrency interviewsIndustries Software development, Technology, Telecom

Question

Simulate token-ring mutual exclusion. N nodes are arranged in a ring (0..N-1); a single token starts at node 0 and circulates 0→1→...→N-1→0. At each tick the token is held by exactly one node. requests is a list of [tick, node] meaning 'node' wants to enter its critical section at that tick (each request stands until satisfied). A node may enter the critical section ONLY when it currently holds the token AND it has an outstanding (already-issued at or before the current tick) request; entering consumes that request. Whether or not a node enters, the token advances one step per tick (to (holder+1) mod N) at the end of each tick. Simulate for exactly 'ticks' ticks (tick indices 0..ticks-1). Return the list of [tick, node] critical-section entries in chronological order.

Implement
token_ring(n: int, requests: list[list[int]], ticks: int) → list[list[int]]
Examples
in[3,[[0,0],[0,2]],5]out[[0,0],[2,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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.