Show problems as
Classic problem #412EasyMathStringSimulation

Fizz Buzz

Real-world version: Drum Pattern Callouts
Tracked in this browser only
Read Fizz Buzz on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A drum teacher runs a counting drill. The class counts beats out loud from 1 up to beats, but two beat families get a spoken cue instead of a number:

  • a beat whose number is a multiple of 3 is called as "Tap"
  • a beat whose number is a multiple of 5 is called as "Thud"
  • a beat that is a multiple of both families is called as "TapThud"
  • every other beat is called by its own number, written in decimal with no padding

Return the list of callouts for the whole drill, one string per beat, in beat order. The returned list has exactly beats entries and the entry at position i describes beat i + 1.

Examples

Example 1

Input
beats = 4
Output
["1", "2", "Tap", "4"]

Only beat 3 lands on a cue family, so the other three beats are spoken as plain numbers.

Example 2

Input
beats = 16
Output
["1", "2", "Tap", "4", "Thud", "Tap", "7", "8", "Tap", "Thud", "11", "Tap", "13", "14", "TapThud", "16"]

Beat 15 belongs to both families, so its callout joins the two cues in that order; beats 6, 9 and 12 take the first cue and beat 10 takes the second.

Example 3

Input
beats = 1
Output
["1"]

A one-beat drill produces a single callout, the number itself.

Constraints

  • 1 <= beats <= 10^4

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def drum_labels(beats: int) -> list[str]:
Java
public List<String> drumLabels(int beats)