Recursively Sum Identical Digit Runs
Problem statement
Given a decimal digit string, replace every maximal repeated-digit run by the decimal representation of digit × run length. Single-character runs remain that digit.
Repeat whole passes when a replacement creates adjacent equal digits, stopping when all adjacent digits differ. Return the final string.
Function
compressDigitRuns(digits: String) → StringExamples
Example 1
digits = "66644319333"return = "26328"Repeated passes collapse the newly adjacent digits until no equal neighbors remain.
Example 2
digits = "123"return = "123"No run needs replacement.
Constraints
1 <= digits.length <= 100000