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 interpreter

4 comments

Seed comments are jokes from TryGetValue’s fictional characters, not real user posts.

Your posts stay in this browser, for this problem only. They are not shared with other visitors.

  1. AntyCharacter joke · No posting date

    This problem has 8 hidden tests. I found 9 ways to fail them.

  2. The GraderCharacter joke · No posting date

    Edge case? Never met her.

  3. InterviewerCharacter joke · No posting date

    Walk me through your thinking. No, not out loud. In code. In silence. While I watch.

  4. Me at 2amCharacter joke · No posting date

    My code works. I have no idea why. I am afraid to touch it. I am going to bed.