v9.1.1
Menu

FizzBuzz

easyPROMath & DesignMicrosoft DSA

Given integer n, return a list where for each number 1 to n:

  • "FizzBuzz" if divisible by 3 and 5
  • "Fizz" if divisible by 3
  • "Buzz" if divisible by 5
  • The number as string otherwise

Output each on a separate line.

Example

Input
15
Output
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
Reasoning
  • We start by iterating over the numbers from 1 to the input number, n=15n = 15.
  • For each number ii, we check its divisibility by 3 and 5, and apply the corresponding rules:
    • if ii is divisible by both 3 and 5, we output "FizzBuzz"
    • if ii is divisible by 3, we output "Fizz"
    • if ii is divisible by 5, we output "Buzz"
    • otherwise, we output the number as a string.
  • We repeat this process for all numbers from 1 to nn, resulting in the output list with each item on a separate line.
  • The rules are applied as follows:
    • 33 is divisible by 3, so "Fizz" is output
    • 55 is divisible by 5, so "Buzz" is output
    • 1515 is divisible by both 3 and 5, so "FizzBuzz" is output.

Constraints

  • 1 <= n <= 10^4

More from Microsoft DSA

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.