All problems
RLE Compression Ratio
Problem
Run-length encoding stores every maximal run as a value plus a run count, so it needs 2 * runs integers for n input values. Return the ratio of encoded length to original length, which is 2 * runs / n. Return 0.0 for an empty list.
Hint
Long runs make the ratio small, while alternating values make it approach 2.
Test cases
case 1
in: [[1,1,1,1]]
expected: 0.5
case 2
in: [[1,2,3]]
expected: 2
case 3
in: [[1,1,2,2,2,1]]
expected: 1
case 4
in: [[]]
expected: 0
Starter codePython
def rle_compression_ratio(values):
# Your code here
pass4 test cases · run your code against them in the editor