Practice

Run-Length Compressor

HARDString Processing9 marks

Read an uppercase word and compress each run of consecutive equal letters.

For every run, output the letter followed by the number of times it appears consecutively.

Input: One uppercase word with at least one character. Output: The compressed string.

Example:

Input:  AAABBCCCC
Output: A3B2C4
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Several runs
Inputs: AAABBCCCC
Expected: A3B2C4
Test 2: No repeated letters
Inputs: XYZ
Expected: X1Y1Z1
Test 3: One long run
Inputs: AAAAA
Expected: A5