Practice Print Zero Even Odd
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Implement ZeroEvenOdd(n) for three threads sharing the same object. The zero(printNumber) method prints zeros, even(printNumber) prints positive even numbers, and odd(printNumber) prints positive odd numbers. Coordinate them to print the numbers 1 through n in increasing order, with a zero immediately before each number: 0, 1, 0, 2, 0, 3, and so on. Use the supplied printNumber callback for each output integer. The sequence contains 2 * n printed integers.
Source: Print Zero Even Odd on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 2
"0102"
# Example 2
n = 5
"0102030405"
Constraints
Related LeetCode Problems
Practice more problems similar to Print Zero Even Odd.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.