Drum pattern rolls

Write codeMedium14 min

Your task

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.

Examples

count_drum_plays(pattern: str) -> int
Example 1
Inputcount_drum_plays("112")
Output2
Example 2
Inputcount_drum_plays("1111")
Output5