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

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

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started