String Compression
Medium 40 XPStrings
Commonly asked at Zoho, Amazon, Microsoft
Compress a word by replacing each run of the same character with the character followed by the run length. For example aaabbc becomes a3b2c1.
- Input
- One word.
- Output
- The compressed word.
Sample 1
Input
aaabbc
Output
a3b2c1
Read input with input() (no prompt message) and print only the answer. Run tries the Input box; Submit checks all test cases.
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.The solution unlocks after 3 submissions.