Search⌘ K
AI Features

Solution: String Compression III

C# solution for the String Compression III problem using the Knowing What to Track pattern.

Statement

You are given a string word. Build a new string comp by repeatedly taking a non empty prefix of the remaining word, removing that prefix from word, and appending an encoded form of the prefix to comp.

A prefix can be encoded only if it consists of a single repeated character, and its length is at most 99. If the chosen prefix has length k and character c, append the string representation of k followed by c to comp.

Return the final value of comp after the entire word has been processed.

Note: Each encoded group must have length at most 9 ...