You are given a list nums that run-length encodes another list. Read it as adjacent pairs [freq, val] = [nums[2*i], nums[2*i+1]]: each pair stands for freq copies of the value val. Concatenate the expanded pairs from left to right and return the decompressed list.
You are given a list nums that run-length encodes another list. Read it as adjacent pairs [freq, val] = [nums[2i], nums[2i+1]]: each pair stands for freq copies of the value val. Concatenate the expanded pairs from left to right and return the decompressed list.
Example 1:
Input: {"nums":[1,2,3,4]}
Output: [2,4,4,4]
Constraints:
2≤nums.length≤100
nums.lengthmod2=0
1≤nums[i]≤100
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,2,3,4]}
nums holds 2 pairs of [freq, val]. Start with an empty result and expand each pair in order.
encoded nums, read two at a time: freq then val
1
2
3
4
no pair read yet
result (0 values)
[ ]
0 of 2 pairs expanded; each color is one pair's run