Write each run of letters once
A run is a stretch of the same letter, side by side, that cannot be made longer. Squeeze a string by writing every run of 2 or more letters as the letter followed by the run's length. A letter that stands alone stays as it is.
For each string, print it squeezed.
Input
The first line holds T, the number of tests. Each test is one line holding one string of lowercase letters.
Output
For each test, one line: its string, squeezed.
- Input
4
aaabccddd
xyz
aabaa
qqqqqqqqqqqq- Output
a3bc2d3
xyz
a2ba2
q12
- The runs of a, c and d become the letter and its length; the lone b stays as it is.
- No letter sits next to itself, so nothing changes.
- Only letters side by side make a run: the two runs of a are written apart.
- A long run gives a length of more than one digit.
Limits
1 <= T <= 100each string holds 1 to 100000 lettersall the strings together hold at most 400000 letters
Hints
Hint 1
Walk the string with two positions: the start of a run, and the first letter after it.
Hint 2
Building the answer by adding to a string one piece at a time can be slow in some languages: collect the pieces and join them once.
Where this was reported
- IBM, Software developer on-campus interview, 2025 (GeeksforGeeks)
Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.
Run your code to check it on the examples. Submit runs every hidden test.
