Fizz Buzz - Problem
Given an integer n, return a string array answer (1-indexed) where:
answer[i] == "FizzBuzz"ifiis divisible by 3 and 5.answer[i] == "Fizz"ifiis divisible by 3.answer[i] == "Buzz"ifiis divisible by 5.answer[i] == i(as a string) if none of the above conditions are true.
Input & Output
Example 1 — Basic Case
$
Input:
n = 3
›
Output:
["1","2","Fizz"]
💡 Note:
Numbers 1-3: 1 and 2 are not divisible by 3 or 5, so output as strings. 3 is divisible by 3, so output "Fizz".
Example 2 — Include Buzz
$
Input:
n = 5
›
Output:
["1","2","Fizz","4","Buzz"]
💡 Note:
Numbers 1-5: 1,2,4 output as strings. 3 divisible by 3 → "Fizz". 5 divisible by 5 → "Buzz".
Example 3 — Include FizzBuzz
$
Input:
n = 15
›
Output:
["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
💡 Note:
Numbers 1-15: 15 is divisible by both 3 and 5, so output "FizzBuzz". Other multiples follow individual rules.
Constraints
- 1 ≤ n ≤ 104
Visualization
Tap to expand
Understanding the Visualization
1
Input
Integer n representing the range 1 to n
2
Process
Apply FizzBuzz rules to each number
3
Output
String array with transformed values
Key Takeaway
🎯 Key Insight: Use modulo operations to efficiently determine divisibility and apply the correct FizzBuzz transformation rule.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code