Ctrl K

Counting Off by Threes and Fives

Easy
Players take turns counting from 1 to n, with a twist: - a number divisible by both 3 and 5 is replaced by "FizzBuzz"; - a number divisible only by 3 is replaced by "Fizz"; - a number divisible only by 5 is replaced by "Buzz"; - any other number is said as is (as a string, e.g. "7"). Return the list of n strings spoken during the game, in order.
Example 1
n=6 → ['1', '2', 'Fizz', '4', 'Buzz', 'Fizz']

3 and 6 are multiples of 3 ("Fizz"), 5 is a multiple of 5 ("Buzz"), the rest are said as numbers.

Example 2
n=15 → ['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz']

15 is a multiple of both 3 and 5, so the last player says "FizzBuzz".

Example 3
n=1 → ['1']
Constraints
  • 1 ≤ n ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyAdding Long Numbers in Strings EasyTop of a Digit Pyramid EasyMultiplying Digit Strings MediumMultiply Complex Numbers in Strings Medium
loading Python…
Input
n=6
Expected
['1', '2', 'Fizz', '4', 'Buzz', 'Fizz']

Run checks the first 3 tests in your browser. Submit checks all 47 tests on the server, hidden ones included.