Search⌘ K
AI Features

Solution: String Compression

Explore how to apply the two pointers technique to compress a string array in place. Understand run-length encoding by grouping consecutive characters and writing counts directly into the input array while maintaining constant extra space.

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 ...