#1313
Easy Algorithms Decompress run length encoded list
Array
86.2% acceptance
Feb 25, 2026
1343
1325
We are given a list nums of integers representing a list compressed with run-length encoding.
Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0). For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.
Return the decompressed list.
Solution
Rust
Time O(n²)
Space O(n)
impl Solution {
pub fn decompress_rl_elist(nums: Vec<i32>) -> Vec<i32> {
let mut res = Vec::new();
let mut i = 0;
while i < nums.len() {
let freq = nums[i] as usize;
let val = nums[i + 1];
for _ in 0..freq {
res.push(val);
}
i += 2;
}
res
}
}