Search⌘ K
AI Features

Solution: String Compression

Understand how to implement string compression by applying the two pointers technique to perform run-length encoding in place. This lesson helps you modify the input array directly, write compressed characters efficiently, and return the new length while using constant extra space and linear time.

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