A warehouse printer stores each shelf label in run-length form to save ink. Given a label consisting of lowercase English letters, encode it by scanning left to right and replacing every maximal run of one repeated character with that character immediately followed by the decimal length of the run. The length is always written out, even when it is 1.
For instance, a run of four as becomes a4, and a lone b becomes b1.
Line 1: a non-empty string of lowercase English letters.
A single line: the run-length encoding, formed by concatenating <character><run length> for each run in order.
a-z).Example 1
Input
aaabbc
Expected
a3b2c1
Explanation
Runs are aaa (a3), bb (b2), c (c1), so the encoding is 'a3b2c1'.
Example 2
Input
z
Expected
z1
Explanation
A single character is one run of length 1, encoded as 'z1'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →