All problems
Run-Length Decode
Problem
Decode a run-length encoded vector.
pairs is a list of [count, value] pairs; each pair expands to count copies of value. A count of zero contributes nothing.
Return the decoded list.
Hint
Multiply a one-element list by the count and extend the output.
Test cases
case 1
in: [[[2,"a"],[1,"b"],[3,"a"]]]
expected: ["a","a","b","a","a","a"]
case 2
in: [[]]
expected: []
case 3
in: [[[0,5]]]
expected: []
case 4
in: [[[2,-1],[2,0]]]
expected: [-1,-1,0,0]
Starter codePython
def rle_decode(pairs):
# Your code here
pass4 test cases · run your code against them in the editor