Practice Fizz Buzz
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
Produce one string for each integer from 1 through n. Use FizzBuzz for multiples of both 3 and 5, Fizz for multiples of 3 only, Buzz for multiples of 5 only, and the decimal number otherwise. Keep the strings in numerical order. Practice approach: Test divisibility by 15 first, then 3 and 5. This handles the overlap without accidentally returning only Fizz or Buzz. Runtime and output space are O(n).
Source: Fizz Buzz on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 3
["1","2","Fizz"]
# Example 2
n = 5
["1","2","Fizz","4","Buzz"]
# Example 3
n = 15
["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
Constraints
Related LeetCode Problems
Practice more problems similar to Fizz Buzz.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.