Run-Length Encoding
Asked at Google
Reported by the problem's creator, not verified
A long list of integers with many equal neighbours is often stored as runs instead of raw values. A run is a pair [value, run_length]: run_length consecutive positions that all hold value. A stored list is an ordered list of runs that covers the whole list, and neighbouring runs never hold the same value.
Implement a class RunLength with methods for working with this format.
Examples
Example 1
Input: init =
[], operations =[["encode",[[3,3,3,0,0,0,4,4]]]]Output:
[[[3,3],[0,3],[4,2]]]Explanation: The vector starts with three 3s, then three 0s, then two 4s, which gives three runs.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.