
Fizz Buzz (easy)
Problem Statement
Given an integer n, return a 1-indexed string array res where:
res[i] == "FizzBuzz"if i is divisible by 3 and 5.res[i] == "Fizz"if i is divisible by 3.res[i] == "Buzz"if i is divisible by 5.res[i] == i(as a string) if above all conditions are false.
Examples
-
Example 1:
- Input: 4
- Expected Output: ["1", "2", "Fizz", "4"]
- Justification: 3 is divisible by 3, so it's replaced with "Fizz". The rest are not divisible by 3 or 5, so they remain unchanged.
-
Example 2:
- Input: 7
- Expected Output: ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7"]
- Justification: 3 and 6 are divisible by 3 (replaced with "Fizz"), 5 is divisible by 5 (replaced with "Buzz"), and the rest are printed as is.
-
Example 3:
- Input: 16
- Expected Output: ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16"]
- Justification: 3, 6, 9, and 12 are divisible by 3 ("Fizz"), 5 and 10 are divisible by 5 ("Buzz"), and 15 is divisible by both 3 and 5 ("FizzBuzz"). The rest are printed as is.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory