FastPrepRecursively Sum Identical Digit Runs

Recursively Sum Identical Digit Runs

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

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) → String

Examples

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

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String compressDigitRuns(String digits) {
    // Write your code here.
}
digits"66644319333"
expected"26328"
Checking account…