Two threads share one FooBar instance:
- Thread A calls
foo(printFoo). - Thread B calls
bar(printBar).
The printFoo callback outputs "foo", while printBar outputs "bar". Modify the FooBar class so the two threads produce "foobar" exactly n times.
The judge creates the shared object, starts both 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:
Example 2:
Input:
Output:
Constraints
1 <= n <= 1000foo and bar are called concurrently on the same FooBar instance.- The supplied callbacks are thread-safe and should each be invoked exactly
n times.