Easy · Strings

Run length encoding

Given an ASCII string s, return its run-length encoding: each maximal run of equal adjacent characters becomes that character followed by the run's length in decimal ("aaabbc" → "a3b2c1"); an empty s returns "".

Examples

Example 1

{
  "s": "aaabbc"
}

Output: "a3b2c1"

Example 2

{
  "s": "wwwwaaa"
}

Output: "w4a3"

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Strings problems