Given a string `word`, build a string `comp` as follows. Start with `comp` empty. While `word` is not empty, remove the longest prefix of `word` made of a single character `c` repeated at most 9 times, and append the length of that prefix followed by `c` to `comp`. Return `comp`.
Given a string word, build a string comp as follows. Start with comp empty. While word is not empty, remove the longest prefix of word made of a single character c repeated at most 9 times, and append the length of that prefix followed by c to comp. Return comp.
Example 1:
Input: {"word":"abcde"}
Output: 1a1b1c1d1e
Constraints:
1≤word.length≤2⋅105
word consists only of lowercase English letters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"word":"abcde"}
word (5 letters): packed · window i..j
a
1a
b
1b
c
1c
d
1d
e
1e
comp starts empty. Each piece will be a count from 1 to 9 followed by one letter.