32. Decompress Run-Length Encoded List

EasyArrayArray

A run-length encoded list is given as nums where for each pair (freq, val) at indices [2i, 2i+1], the value val should appear freq times in the decompressed list. Return the decompressed list.

Input: An integer array nums of even length where pairs represent (frequency, value).

Output: Decompressed integer array.

Examples

Example 1
Input: [1,2,3,4]
Output: [2,4,4,4]
Explanation: Pair (1,2): one 2 → [2]. Pair (3,4): three 4s → [4,4,4]. Combined: [2,4,4,4].
Example 2
Input: [1,1,2,3]
Output: [1,3,3]
Explanation: Pair (1,1): one 1 → [1]. Pair (2,3): two 3s → [3,3]. Combined: [1,3,3].
Example 3
Input: [2,4,3,1,2,2]
Output: [4,4,1,1,1,2,2]
Explanation: Pair (2,4): [4,4]. Pair (3,1): [1,1,1]. Pair (2,2): [2,2]. Combined: [4,4,1,1,1,2,2].

Constraints

Asked by

GoogleMicrosoft
Solve this problem in the editor →