easy
strings
math
Return strings for the integers from 1 through n. Use "FizzBuzz" for multiples of both 3 and 5, "Fizz" for multiples of 3, "Buzz" for multiples of 5, and the decimal number otherwise.
Input / output
- Input:
n: integer - Output:
string[]of lengthn
Examples
n = 5returns["1","2","Fizz","4","Buzz"].- At
n = 15, the final value is"FizzBuzz".
Constraints
1 <= n <= 10,000
Follow-up How would you make the rules data-driven so new divisors and labels can be added without another conditional branch?
Examples
Example 1
Input: n = 5
Output: ["1","2","Fizz","4","Buzz"]
Example 2
Input: n = 15
Output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
Example 3
Input: n = 3
Output: ["1","2","Fizz"]
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.