16. Run-length encoding
Run-length encoding replaces each run of equal, adjacent characters by the character and the length of the run. Write rle s, the encoding of the string s as a list of pairs.
For "aaabcc" the runs are three 'a', one 'b' and two 'c'.
Examples
- Input
rle "aaabcc"Output[('a', 3), ('b', 1), ('c', 2)] - Input
rle ""Output[]
Submitting also runs 5 hidden tests.
Constraints
- Upper- and lower-case letters are different characters.
Running and submitting solutions, the hints and the editorial come with the Academy Pass. The daily problem is open to every account.
Loading editor…
Type
\to in the editor, or click:Run checks your code against the examples and your custom inputs and records nothing. Submit also runs the hidden tests, confirms the axioms your proof uses and records the result. Each uses one compiler check.
ReadyLn 1, Col 1Lean 4
Draft saved in this browser