Skip to content

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.

Easy#412
LeetCode Problem

Fizz Buzz

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

Input
n = 3
Output
["1","2","Fizz"]

# Example 2

Input
n = 5
Output
["1","2","Fizz","4","Buzz"]

# Example 3

Input
n = 15
Output
["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]

Constraints

1 <= n <= 10000

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.