Problem · String
String Compression Problem
Learn this problemProblem statement
Given a string input, replace each maximal consecutive run of the same character with that character followed by the run length.
Return the complete run-length encoded string, even when it is longer than input.
Function
compressString(input: String) → StringExamples
Example 1
input = "abaasass"return = "a1b1a2s1a1s2"
The consecutive runs are a, b, aa, s, a, and ss. Writing each run as its character followed by its length produces a1b1a2s1a1s2.