In-Place Run-Length Compression of a Character Array

Asked at Salesforce · Coding Questions · Difficulty: Medium · Last asked Apr 3, 2026

Given an array of characters, compress each run of identical consecutive characters in place. A run of length 1 is kept as the single character. A run of length `k >= 2` is replaced by the character followed by the decimal digits of `k`, one digit per array cell. After compressing, the first part of the array holds the compressed text, and the function returns that part's length.

Loading the problem…