Leetcode #1313: Decompress Run-Length Encoded List
In this guide, we solve Leetcode #1313 Decompress Run-Length Encoded List in Python and focus on the core idea that makes the solution efficient.
You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Problem Statement
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[2i], nums[2i+1]] (with i >= 0).
Quick Facts
- Difficulty: Easy
- Premium: No
- Tags: Array
Intuition
The constraints allow a direct scan that keeps only the essential state.
By translating the requirements into a clean loop, the logic stays easy to reason about.
Approach
Iterate through the data once, updating the state needed to compute the answer.
Return the final state after the traversal is complete.
Steps:
- Parse the input.
- Iterate and update state.
- Return the computed answer.
Example
Input: nums = [1,2,3,4]
Output: [2,4,4,4]
Explanation: The first pair [1,2] means we have freq = 1 and val = 2 so we generate the array [2].
The second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4].
At the end the concatenation [2] + [4,4,4] is [2,4,4,4].
Python Solution
class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
return [nums[i + 1] for i in range(0, len(nums), 2) for _ in range(nums[i])]
Complexity
The time complexity is , where is the length of the array . The space complexity is .
Edge Cases and Pitfalls
Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.
Summary
This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.