PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates a candidate's ability to implement basic control flow, use modulo operations, iterate over sequences, and reason about time and space complexity. It is commonly asked to verify fundamental programming proficiency and algorithmic reasoning, and it belongs to the coding & algorithms domain with both practical implementation focus and conceptual complexity analysis.

  • medium
  • Uber
  • Coding & Algorithms
  • Data Scientist

Implement FizzBuzz

Company: Uber

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Write a function that takes an integer `n` and outputs the numbers from 1 to `n` using the standard FizzBuzz rules: - output `Fizz` for numbers divisible by 3 - output `Buzz` for numbers divisible by 5 - output `FizzBuzz` for numbers divisible by both 3 and 5 - otherwise output the number itself Discuss the time and space complexity of your solution.

Quick Answer: This question evaluates a candidate's ability to implement basic control flow, use modulo operations, iterate over sequences, and reason about time and space complexity. It is commonly asked to verify fundamental programming proficiency and algorithmic reasoning, and it belongs to the coding & algorithms domain with both practical implementation focus and conceptual complexity analysis.

Write a function that takes an integer n and returns the FizzBuzz sequence from 1 to n. For each number i from 1 to n: - return "Fizz" if i is divisible by 3 - return "Buzz" if i is divisible by 5 - return "FizzBuzz" if i is divisible by both 3 and 5 - otherwise return the number itself as a string If n is less than or equal to 0, return an empty list.

Constraints

  • -100000 <= n <= 100000
  • If n <= 0, the result should be an empty list

Examples

Input: (5,)

Expected Output: ['1', '2', 'Fizz', '4', 'Buzz']

Explanation: Numbers 3 and 5 are replaced with "Fizz" and "Buzz" respectively.

Input: (15,)

Expected Output: ['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz']

Explanation: 15 is divisible by both 3 and 5, so it becomes "FizzBuzz".

Input: (1,)

Expected Output: ['1']

Explanation: With n = 1, the sequence contains only the string form of 1.

Input: (0,)

Expected Output: []

Explanation: There are no numbers from 1 to 0, so the result is empty.

Input: (-3,)

Expected Output: []

Explanation: For negative n, return an empty list.

Hints

  1. A number divisible by both 3 and 5 needs special handling, so think carefully about the order of your checks.
  2. Since the output includes words like "Fizz" and "Buzz", it is easiest to store every result as a string.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Minesweeper and Word Search - Uber (medium)
  • Implement Store Autocomplete - Uber (medium)
  • Implement Cache Eviction And Seat Assignment - Uber (medium)
  • Schedule Non-Overlapping Meetings Efficiently - Uber (hard)
  • Evaluate an Arithmetic Expression - Uber