Search⌘ K
AI Features

Solution: String Compression

Explore how to use the two pointers technique to compress a string in place by applying run-length encoding. This lesson teaches you to identify consecutive character groups, overwrite the input array with compressed output efficiently, and achieve this using constant extra space, improving your coding interview skills.

Statement

Given an array of characters, chars, compress it in place according to the following rules:

  1. Start with an empty string s.

  2. For each group of consecutive repeating characters in chars:

    1. If the group length is ...