All tasks
Mediumstringsloops

Run-Length Encoding

Time limit 2 s · Memory 64 MBAcceptance: —Solved by: 0

Statement

You are given a string of lowercase Latin letters. Replace every maximal run of equal letters with "letter + count". For example, aaabbc becomes a3b2c1. A count of 1 is written too.

Examples

Example 1
Input
aaabbc
Output
a3b2c1
Example 2
Input
abc
Output
a1b1c1

Constraints

  • String length is between 1 and 10^5
Solve this task to unlock the editorial.

AI tutor

Stuck? Get a nudge — the tutor explains the idea, it never hands you the solution.