Fizz Buzz

Given an integer n, return a string array answer (1-indexed) where:

  • answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
  • answer[i] == "Fizz" if i is divisible by 3.
  • answer[i] == "Buzz" if i is divisible by 5.
  • answer[i] == i (as a string) if none of the above conditions are true.
Example 1
Inputn = 3
Output["1","2","Fizz"]
For numbers 1 through 3, only 3 is divisible by 3, so it is replaced with "Fizz".
Example 2
Inputn = 5
Output["1","2","Fizz","4","Buzz"]
For numbers 1 through 5, 3 becomes "Fizz" and 5 becomes "Buzz".

Constraints

  • 1 <= n <= 10^4

Asked at 19 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate