Practice String Compression III
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Compress word by repeatedly taking its longest prefix consisting of one repeated character, limited to at most nine characters. Append the prefix length followed by that character to the result, then remove the prefix and continue. Return the resulting string.
Source: String Compression III on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
word = "abcde"
Output
"1a1b1c1d1e"
# Example 2
Input
word = "aaaaaaaaaaaaaabb"
Output
"9a5a2b"
Constraints
1 <= word.length <= 2 * 10^5
word consists only of lowercase English letters.
Related LeetCode Problems
Practice more problems similar to String Compression III.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.