Implement FizzBuzz
Company: Uber
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
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.
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
- A number divisible by both 3 and 5 needs special handling, so think carefully about the order of your checks.
- Since the output includes words like "Fizz" and "Buzz", it is easiest to store every result as a string.