Problem 250398 · easy · Phase 02 Linear Data Structures

Expand Run-Length Pairs

arrays · run-length encoding · list building

Given a list pairs of [value, count] pairs, rebuild the original list: each pair contributes count copies of value, in order. A count of 0 contributes nothing.

Examples

Input:  pairs = [[1, 2], [2, 1], [3, 3]]
Output: [1, 1, 2, 3, 3, 3]

Input:  pairs = [[9, 0], [4, 2]]
Output: [4, 4]

Constraints

  • 0 <= len(pairs) <= 10**5, all counts >= 0, total output length <= 10**5
  • Return a new list.
  • Target: O(output length) time.

Goals

  • Expand each pair into repeated values with extend
  • Handle a zero count that contributes nothing
  • Build the result in a single pass
Starting Python…