Search⌘ K

DIY: String Compression

Explore how to compress a list of characters by encoding consecutive repeating groups with their counts while maintaining constant space complexity. This lesson guides you in modifying the input directly and returning the new compressed length, helping you understand key data manipulation strategies useful for coding interviews.

Problem statement

You are given a list of characters. Your task will be to compress this list, using the following algorithm:

For each group of consecutive repeating characters in the string:

  1. If the group’s length is 1, you will append the character to s.
...