EasyArraysAI interview only
Decompress Run Length Encoded List
Asked atamazongoogleapple
01 · Problem
A list has been compressed with run-length encoding into the integer array nums. The array is read as consecutive pairs [freq, val] = [nums[2*i], nums[2*i + 1]], and each pair stands for freq copies of val.
Rebuild the original list by expanding every pair in order from left to right and concatenating the results. Return the decompressed list.
02 · Examples
Example 01
Input
nums = [2,7,1,3]
Output
[7,7,3]
The pairs are [2,7] and [1,3], which expand to [7,7] and [3]. Concatenated: [7,7,3].
Example 02
Input
nums = [1,4,3,9]
Output
[4,9,9,9]
The pairs are [1,4] and [3,9], which expand to [4] and [9,9,9].
Example 03
Input
nums = [3,5]
Output
[5,5,5]
A single pair [3,5] expands to three copies of 5.
03 · Constraints
- 012 <= nums.length <= 100
- 02nums.length is even
- 031 <= nums[i] <= 100
04 · Optimal complexity
- Time
- O(n + S)
- Space
- O(1)
05 · Two ways to work on it
Practice it alone or rehearse it as an interview.
Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.