All problems
0131EasyMathStringSimulation

Drum Pattern Callouts

Tracked in this browser only
Write code

Trains the technique from

LeetCode 412Fizz Buzz

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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