Code Room
CodingMediumcod-g1476
Subject Dynamic programming 1dLevel Entry–Mid~14 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.