Merge K Sorted Runs
medium · k-way merge
Merge a list of sorted integer runs into one ascending list. Preserve duplicate values. Runs can be empty; there may be zero runs. Each run is already nondecreasing. Use a heap with at most one pending value per nonempty run, rather than flattening and sorting all values. Return values only, so equal values are indistinguishable.
Examples (JSON; null means Python None):
Input: {"runs": [[1, 4], [1, 3, 5], [2, 6]]}
Output: [1, 1, 2, 3, 4, 5, 6]
Input: {"runs": [[], [-2, 0], []]}
Output: [-2, 0]
Starter code
def merge_runs(runs: list[list[int]]) -> list[int]:
"""Merge sorted runs using a bounded frontier."""
pass
Loading editor…
Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.
Return to the Python compiler