30. String Compression
EasyStringRun-Length Encoding
Compress a string with run-length encoding: replace each run of identical characters by the character followed by the run length (aaabbc → a3b2c1).
Input format
A single string of lowercase letters.
Output format
The compressed string.
Example 1
Input
aaabbc
Output
a3b2c1
Example 2
Input
abc
Output
a1b1c1
Constraints
1 ≤ length ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…