Practice Print in Order
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
Three threads share one Foo object. One calls first(), which prints "first"; another calls second(), which prints "second"; and the third calls third(), which prints "third". Synchronize these methods so that the complete output is always "firstsecondthird", regardless of the order in which the threads are scheduled. The input order does not guarantee execution order.
Source: Print in Order on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,2,3]
"firstsecondthird"
# Example 2
nums = [1,3,2]
"firstsecondthird"
Constraints
Related LeetCode Problems
Practice more problems similar to Print in Order.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.