FreeCareerPath
Build the PrimitiveHard

Merge k Sorted Lists

Write `merge_k_lists(lists)` merging `k` ascending linked lists into one and returning its head. The input may contain empty lists. Merging them one at a time into an accumulator is O(n k) — say so, then do better. Two options reach O(n log k): a min-heap holding the current head of each list, or repeatedly merging pairs of lists. Pick one and be able to justify the bound.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Merge k Sorted Lists" are saved to your account — logging in takes a few seconds.