Concurrency design problem (paper-only). This problem exercises threading / synchronisation primitives that the gitGood code-execution sandbox does not expose. The auto-grader instead validates a single-threaded simulation of the protocol so you can still verify your scheduler logic; in a real interview you would write the multi-threaded version.
You have a class ZeroEvenOdd shared by three threads:
- Thread A repeatedly calls
zero(), which prints0. - Thread B repeatedly calls
even(), which prints an even number. - Thread C repeatedly calls
odd(), which prints an odd number.
For a given integer n, the three threads collectively print the sequence 0102030405... up through n, i.e. for n = 5 the output is "0102030405". The threads coordinate using two semaphores (one gating even, one gating odd). Thread A toggles which side it releases after each zero.
For the auto-grader: implement zeroEvenOdd(n) that returns the string the three threads would collectively produce for input n. Your single-threaded simulation must follow the protocol described in the explanation (don't just return "01020304..." by string concatenation - work through the state machine).