Code RoomDrum pattern rolls
MediumPrep Room Coding #678

Drum pattern rolls

CodingAlgorithms & data structuresEntry–Mid~14 min

A drum machine stores a pattern as a non-empty string of digits, one digit per pad hit. When two identical digits sit next to each other, a performer may either play them as two separate hits or merge them into a single roll. Different digits can never merge, and a roll always covers exactly two characters. Return the number of distinct ways to perform the whole pattern. For example, "112" can be played as 1|1|2 or as 11|2, so the answer is 2.

Implement
count_drum_plays(pattern: str) → int
Examples
in["112"]out2
in["1111"]out5
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 14 min
InputExpectedGot
["112"]2not run yetsample
["1111"]5not run yetsample