Ctrl K

Unpack Count-Value Pairs

Easy
A warehouse stores long lists in compact form: instead of repeating numbers it writes "count, value" pairs. The array packed is a sequence of such pairs: packed[0] says how many times to repeat packed[1], packed[2] says how many times to repeat packed[3], and so on. Rebuild the original list: expand each pair into that many copies of its value and join the pieces left to right, in the order the pairs appear.
Example 1
packed=[2, 7, 1, 3] → [7, 7, 3]

The pair (2, 7) gives two 7s and the pair (1, 3) gives one 3: [7, 7, 3].

Example 2
packed=[3, 5, 2, 5] → [5, 5, 5, 5, 5]

Neighbouring pairs may share a value: three 5s and then two more, five in total.

Example 3
packed=[1, 100] → [100]
Constraints
  • 2 ≤ len(packed) ≤ 100
  • len(packed) is even
  • 1 ≤ packed[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
packed=[2, 7, 1, 3]
Expected
[7, 7, 3]

Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.