Loading...
Loading...
Loading...
A sensor sends long runs of the same letter, like aabcccccaaa. To save data, each run is sent as the letter followed by its length: a2b1c5a3. Read the text and print the compressed form. Every run gets a count, even a run of 1.
Example 1
Input
aabcccccaaa
Output
a2b1c5a3
The last run of a is separate from the first.
Example 2
Input
abc
Output
a1b1c1
No repeats: every count is 1.
Try the problem first. Open one hint at a time.
Walk through the text and keep a counter for the current run.
When the next character is different, or the text ends, append the letter and the counter, then reset the counter.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor