Decompress Run-Length Encoded List

Easy

Description

Given an encoded list nums = [freq1, val1, freq2, val2, ...], each pair [freqi, vali] means there are freqi copies of vali. Return the decompressed list.

Examples

Input:nums = [1,2,3,4]
Output:[2,4,4,4]
Explanation:

1 copy of 2, 3 copies of 4.

Input:nums = [2,5,4,1]
Output:[5,5,1]
Explanation:

2 copies of 5, then 4 copies of 1. The pairs are processed sequentially: [2,5] gives us two 5's, and [4,1] gives us four 1's.

Input:nums = [1,0,2,7,3,2]
Output:[0,7,7,2,2,2]
Explanation:

1 copy of 0, 2 copies of 7, then 3 copies of 2. Shows how frequency of 1 produces a single element, and demonstrates processing multiple pairs in sequence.

Constraints

  • 2 ≤ nums.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!