
FizzBuzz
easyFizzBuzz
Microsoft Python Interview Question
A Microsoft Teams quiz bot counts from 1 up to a number, but replaces some numbers with words to keep players alert.
Write a function fizz_buzz(n) that returns a list of strings for the numbers 1 to n. Use "Fizz" for multiples of 3, "Buzz" for multiples of 5, "FizzBuzz" for multiples of both, and the number itself, as a string, for everything else.
Asked of
- Data Analyst
- Data Engineer
- Data Scientist
- ML Engineer
- AI Engineer
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"]
Explanation
In the first example, 3 becomes "Fizz" and 5 becomes "Buzz", while 1, 2 and 4 stay as numbers written as strings. In the second example, 15 is a multiple of both 3 and 5, so it becomes "FizzBuzz".
Submit also runs 3 hidden test cases that check edge cases.
Company
Microsoft
Difficulty
easy
Topic
math
Language
Python
Your code
Loading Python in the background. You can start writing.