Programming Interviews: Fizz Buzz

An all-time programming classic for interviews

Martin Thoma
4 min readMar 9, 2021
Photo by Christina @ wocintechchat.com on Unsplash

When companies interview potential new software developers, they typically also have a programming interview to make sure that the candidate can actually write very simple programs. Fizz Buzz is a very simple classical example. The problem is easy to describe and the solution is easy as well.

Problem Statement

Write a function that takes an integer and returns a string. If the number is divisible by 3, return “Fizz”. If the number is divisible by 5, return “Buzz”. If the number is divisible by 15, return “Fizz Buzz”. If the number is not divisible by 3 nor by 5, return the number itself.

Solution

In Python, a solution looks like this:

def fizzbuzz(number: int) -> str:
if number % 15 == 0:
return "Fizz Buzz"
if number % 3 == 0:
return "Fizz"
if number % 5 == 0:
return "Buzz"
return str(number)

Unit Tests

Seeing which cases people test gives a good indicator of how used they are to testing at all. There are two groups of tests I want to see:

  • Typical Cases
  • Edge Cases

--

--

Martin Thoma

I’m a Software Engineer with over 10 years of Python experience (Backend/ML/AI). Support me via https://martinthoma.medium.com/membership