Skip to main content

412. Fizz Buzz

easyAsked at Bloomberg

Bloomberg uses Fizz Buzz as a pure communication test — they want to hear you enumerate edge cases aloud (divisible by both 3 and 5 first), mirroring how Bloomberg engineers articulate business-rule precedence before touching a trading system's branching logic.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Problem

Given an integer n, return a string array answer where: answer[i] == 'FizzBuzz' if i is divisible by both 3 and 5; answer[i] == 'Fizz' if i is divisible by 3; answer[i] == 'Buzz' if i is divisible by 5; answer[i] == i (as a string) otherwise. Indices are 1-based.

Constraints

  • 1 <= n <= 10^4

Examples

Example 1

Input
n = 5
Output
["1","2","Fizz","4","Buzz"]

Example 2

Input
n = 15
Output
["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]

Approaches

1. Conditional chain

For each number, check divisibility in order: 15 first, then 3, then 5, else convert to string.

Time
O(n)
Space
O(n) for output
function fizzBuzz(n) {
  const res = [];
  for (let i = 1; i <= n; i++) {
    if (i % 15 === 0) res.push('FizzBuzz');
    else if (i % 3 === 0) res.push('Fizz');
    else if (i % 5 === 0) res.push('Buzz');
    else res.push(String(i));
  }
  return res;
}

Tradeoff:

2. String accumulation (extensible)

Build the label by concatenating 'Fizz' and 'Buzz' conditionally, then fall back to the number string if the label is empty. Trivially extends to new rules (e.g., 'Jazz' for multiples of 7) without restructuring the conditional chain.

Time
O(n)
Space
O(n) for output
function fizzBuzz(n) {
  const res = [];
  for (let i = 1; i <= n; i++) {
    let label = '';
    if (i % 3 === 0) label += 'Fizz';
    if (i % 5 === 0) label += 'Buzz';
    res.push(label || String(i));
  }
  return res;
}

Tradeoff:

Bloomberg-specific tips

Bloomberg interviewers watching Fizz Buzz are really grading three things: do you handle the combined case without redundancy, do you talk through your logic before typing, and can you extend the solution cleanly when they add a new rule mid-interview? Volunteer the extensible string-accumulation version unprompted — it signals you write for maintainability, a trait Bloomberg's engineering culture prizes in shared financial-system codebases.

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

Practice these live with InterviewChamp.AI

Drill Fizz Buzz and other Bloomberg interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →