Concurrency design problem (paper-only). Threading is not available; the auto-grader validates a simulation of the mutual-exclusion contract.
There is an intersection of two roads. Road A runs north-south (direction 1), road B runs east-west (direction 2). At any moment, only one road can have the green light. Cars arrive at the intersection from one of the two directions; if their direction currently has the green light they pass immediately, otherwise the light flips (preempting one car of "switch overhead") before they pass.
Implement carScheduling(cars) where cars is an array of integers 1 or 2 (the direction of each arriving car, in arrival order). Initially the green light is on direction 1. Return the total number of light-switch events (every time the controller toggles directions). The interview-grade answer uses a single mutex around the light state so the critical section is atomic.