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 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
, so runs longer than must be split into multiple groups.
Constraints:
word.length
word consists only of lowercase English letters.
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 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
, so runs longer than must be split into multiple groups.
Constraints:
word.length
word consists only of lowercase English letters.