FunctionRacerProblemsRace

String Compression

EasyStringsPython, JavaScript, TypeScript, Java, C++

Run-length encode s: replace every run of the same letter by the letter followed by the length of the run, even when the run has length 1. Return the encoded string. An empty string encodes to an empty string.

Example 1

s "aaabcc"
returns "a3b1c2"

Runs aaa, b, cc become a3b1c2.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems