String Compression — JavaScript medium interview problem
Given an array of characters `chars`, compress it using run-length encoding in-place. Groups of consecutive repeating characters are replaced with the character followed by the count (omit count if 1). Digits of multi-digit counts are written as separate characters. Return the new length after compression. Modify `chars` in-place for the first returned length characters. Example: `compress(["a","a","b","b","c","c","c"])` → length `6`, chars begin `["a","2","b","2","c","3"]`.
Tags: two-pointers, run-length
Practice this Strings problem free in the JS Interview Playground with automated tests and unlockable solutions.