File: decompress-run-length-encoded-list/solution.py

Date: 2026-06-06

Time: 16:12

decompress-run-length-encoded-list/solution.py

Purpose

This file solves LeetCode 1313: Decompress Run-Length Encoded List. It takes a run-length encoded list — where consecutive pairs [freq, val] mean "repeat val exactly freq times" — and expands it into the full decompressed list.

Key Components

Solution.addrooms(self, nums: List[int]) -> List[int] — The single method. Note the method name addrooms doesn't match the LeetCode canonical name decompressRLElist; this is a pattern across this repo where solutions use alternative method names.

The contract: given a list of even length where nums[2i] is a frequency and nums[2i+1] is a value, return the expanded list.

Patterns

Dependencies

Imports: typing.List — used only for the type annotation.

Imported by: decompress-run-length-encoded-list/test_solution.py directly. The massive "Imported By" list in the prompt is an artifact of the repo's test infrastructure — all test files share a common import pattern, not a real dependency on this specific solution.

Flow

1. Initialize empty result list.

2. Iterate i over 0, 2, 4, ... up to len(nums) - 1.

3. At each step, nums[i] is the frequency and nums[i+1] is the value.

4. Create a list of nums[i] copies of nums[i+1] and extend result.

5. Return the accumulated result.

For input [1, 2, 3, 4]: iteration 0 produces [2], iteration 1 produces [4, 4, 4], final result is [2, 4, 4, 4].

Invariants

Error Handling

None. The code trusts the caller to provide valid input per the LeetCode contract. An out-of-bounds access on nums[i+1] is the only possible failure mode, and it would propagate as an unhandled IndexError.

Complexity