Skip to content

Practice Fizz Buzz Multithreaded

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1195
LeetCode Problem

Fizz Buzz Multithreaded

Problem Statement

Implement FizzBuzz(n) for four threads sharing one instance. One calls fizz(printFizz), one buzz(printBuzz), one fizzbuzz(printFizzBuzz), and one number(printNumber). Coordinate the callbacks to output one token for each integer i from 1 through n in order: "fizzbuzz" for multiples of both 3 and 5, "fizz" for other multiples of 3, "buzz" for other multiples of 5, and i otherwise. Each method must use its corresponding callback; printNumber receives the integer to print.

Source: Fizz Buzz Multithreaded on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 15
Output
[1,2,"fizz",4,"buzz","fizz",7,8,"fizz","buzz",11,"fizz",13,14,"fizzbuzz"]

# Example 2

Input
n = 5
Output
[1,2,"fizz",4,"buzz"]

Constraints

1 <= n <= 50

Related LeetCode Problems

Practice more problems similar to Fizz Buzz Multithreaded.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.