PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates basic programming and algorithmic reasoning, including control flow, modular arithmetic, string handling, and the ability to analyze time and space complexity.

  • medium
  • Uber
  • Coding & Algorithms
  • Data Scientist

Implement FizzBuzz

Company: Uber

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement the classic **FizzBuzz** problem. Given a positive integer `n`, return the sequence from `1` to `n` as strings with the following rules: - If a number is divisible by `3`, output `"Fizz"` - If a number is divisible by `5`, output `"Buzz"` - If a number is divisible by both `3` and `5`, output `"FizzBuzz"` - Otherwise, output the number itself as a string Example for `n = 15`: `["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]` Discuss time and space complexity.

Quick Answer: This question evaluates basic programming and algorithmic reasoning, including control flow, modular arithmetic, string handling, and the ability to analyze time and space complexity.

Implement the classic **FizzBuzz** problem. Given a positive integer `n`, return the sequence from `1` to `n` as strings with the following rules: - If a number is divisible by `3`, output `"Fizz"` - If a number is divisible by `5`, output `"Buzz"` - If a number is divisible by both `3` and `5`, output `"FizzBuzz"` - Otherwise, output the number itself as a string Example for `n = 15`: `["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]` Discuss time and space complexity.

Constraints

  • 1 <= n <= 10^4
  • Output each value as a string (numbers are stringified).

Examples

Input: (15,)

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

Explanation: The canonical n=15 example: multiples of 3 -> Fizz, of 5 -> Buzz, and 15 -> FizzBuzz.

Input: (1,)

Expected Output: ["1"]

Explanation: Single element; 1 is divisible by neither 3 nor 5, so it stays "1".

Input: (3,)

Expected Output: ["1", "2", "Fizz"]

Explanation: Boundary at the first Fizz.

Input: (5,)

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

Explanation: Boundary at the first Buzz.

Input: (30,)

Expected Output: ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz"]

Explanation: Two full cycles; both 15 and 30 produce FizzBuzz.

Hints

  1. Check divisibility by 15 (i.e., by both 3 and 5) FIRST, before checking 3 or 5 individually — otherwise a multiple of 15 would be caught by the 3-only branch.
  2. Equivalently, check `i % 3 == 0` and `i % 5 == 0` separately and concatenate "Fizz"/"Buzz", falling back to str(i) when neither matches.
  3. Use range(1, n + 1) so the loop is inclusive of n.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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

  • Deep Equality of Two Records - Uber (medium)
  • Shortest Path in a Grid with Blocked Cells - Uber (medium)
  • Design and Implement an LRU Cache - Uber (medium)
  • Reconstruct the Alphabet Order of an Alien Language - Uber (medium)
  • Maximize Throughput and Count Trigger Components - Uber (medium)