Decompress a Pair List
nums is a list of pairs written flat: [freq1, val1, freq2, val2, ...]. Each pair means "val repeated freq times".
Return the list you get by writing out all the pairs in order.
Example 1
nums [1,2,3,4]
returns [2,4,4,4]
One 2, then three 4s: [2, 4, 4, 4].
Constraints
2 <= len(nums) <= 20, even length0 <= freq <= 5
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Find the Highest AltitudeBeginner
- Groups of KBeginner
- Items Within BudgetBeginner
- Kids With the Most CandiesBeginner
- Largest At Least Twice OthersBeginner
- Longest Increasing RunBeginner
- Max Consecutive OnesBeginner
- Peak So FarBeginner