Easy

Quiz

#412 Fizz Buzz

APPROACH

Given integer n, construct and return a 1-indexed string array of length n. For each index i, the corresponding entry follows these rules:

- "FizzBuzz" when i is divisible by both 3 and 5.

- "Fizz" when i is divisible by 3 only.

- "Buzz" when i is divisible by 5 only.

- The decimal string of i otherwise.

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"]
1 of 4
1:00

What is the optimal approach for this problem?