Three threads share one ZeroEvenOdd instance and one supplied printNumber callback:
- Thread A calls
zero(printNumber) and may output only 0. - Thread B calls
even(printNumber) and may output only even numbers. - Thread C calls
odd(printNumber) and may output only odd numbers.
Coordinate the threads so the callback sequence is 0, 1, 0, 2, 0, 3, ... through n. In other words, each number from 1 through n must be preceded by a zero.
The judge creates the shared object, starts all three threads, and calls each method once. Your implementation should coordinate those method calls rather than create threads itself.
The judge also preloads the standard concurrency and callback APIs for each supported language. You do not need to add import, include, or using statements.
Example 1:
Input:
Output:
Explanation: The callback sequence is 0, 1, 0, 2.
Example 2:
Input:
Output:
Constraints
1 <= n <= 1000zero, even, and odd are called concurrently on the same ZeroEvenOdd instance.printNumber(x) outputs the integer x and is thread-safe.