Leetcode - Strings | Substring
412. Fizz Buzz[E]
https://leetcode.com/problems/fizz-buzz/
Description
Write a program that outputs the string representation of numbers from 1 to n.
But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
Example:
1 | n = 15, |
Solution
1 | class Solution: |
https://leetcode.com/problems/fizz-buzz/solution/
1195. Fizz Buzz Multithreaded[M]
https://leetcode.com/problems/fizz-buzz-multithreaded/
Description
Write a program that outputs the string representation of numbers from 1 to n, however:
- If the number is divisible by 3, output “fizz”.
- If the number is divisible by 5, output “buzz”.
- If the number is divisible by both 3 and 5, output “fizzbuzz”.
For example, for n = 15, we output: 1, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz.
Suppose you are given the following code:
1 | class FizzBuzz { |
Implement a multithreaded version of FizzBuzz with four threads. The same instance of FizzBuzz will be passed to four different threads:
- Thread A will call
fizz()to check for divisibility of 3 and outputsfizz. - Thread B will call
buzz()to check for divisibility of 5 and outputsbuzz. - Thread C will call
fizzbuzz()to check for divisibility of 3 and 5 and outputsfizzbuzz. - Thread D will call
number()which should only output the numbers.
Solution
1 |





