Back to problems

String Compression

Algorithm · Salesforce · Medium

Requirements Implement the language-agnostic function compress(chars: character[]) -> integer. You receive a character array named chars. Replace each contiguous block of identical characters with its compressed form. A block containing one character remains unchanged; a block of size k, where k ≥ 2, is represented by that character followed by the base-10 digits of k. Perform the update directly within chars, and return its resulting length. The algorithm may use only O(1)…

Checking your access…