Loading...
Loading...
Loading...
A storage tool shortens runs of the same letter. Each run becomes the letter followed by its length, so aaabbc becomes a3b2c1.
Read one word and print the compressed form. A letter that comes back later starts a new run.
Example
Input
aaabbc
Output
a3b2c1
Runs: aaa, bb, c.
Try the problem first. Open one hint at a time.
Stand on the first letter of a run and move a second index forward while the letter stays the same.
The run length is the distance between the two indexes. Then jump to the end of the run.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor