Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

FizzBuzz Implementation

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is FizzBuzz Implementation. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

A ResMed AirSense reporting utility needs a predictable text representation for a sequence of integer readings. Write fizz_buzz(start, end) to process every integer in the inclusive range from start to end.

For each value:

  1. Return "Fizz Buzz" when it is divisible by both 3 and 5.
  2. Return "Fizz" when it is divisible by 3 but not 5.
  3. Return "Buzz" when it is divisible by 5 but not 3.
  4. Otherwise, return the number converted to a string.

The function must return a list in ascending order. It should not print directly, so the caller can decide whether to display, log, or further process the results. The range is guaranteed to be valid, and divisibility follows Python's integer modulo rules.

Formal Specification

  • Input: Two integers, start and end, where start <= end.
  • Output: A list of strings containing one result for every integer from start through end, inclusive.

Constraints

  • -10^6 <= start <= end <= 10^6
  • 1 <= end - start + 1 <= 10^5
  • The output contains one string for every integer in the inclusive range
  • Multiples of both 3 and 5 must produce "Fizz Buzz"

Function Signature

def fizz_buzz(start, end):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output