Tap here to switch tabs
Problem
Submissions

Problem: String Compression III

med
30 min
Try to solve the String Compression III problem.

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 99, so runs longer than 99 must be split into multiple groups.

Constraints:

  • 1≤1 \leq word.length ≤2⋅105\leq 2 \cdot 10^5

  • word consists only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: String Compression III

med
30 min
Try to solve the String Compression III problem.

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 99, so runs longer than 99 must be split into multiple groups.

Constraints:

  • 1≤1 \leq word.length ≤2⋅105\leq 2 \cdot 10^5

  • word consists only of lowercase English letters.