Coding · must-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix
Merge K Sorted Lists
Problem
You are given an array lists containing the heads of k singly linked lists, each sorted in non-decreasing order. Merge all of them into one sorted linked list and return its head. Nodes should be reused, not copied.
- There are between 0 and 20,000 lists.
- Each list has between 0 and 1,000 nodes; the total number of nodes
Nis at most 50,000. - Node values fit in a signed 32-bit integer.
Examples
lists = [[2, 7, 9], [3, 7, 8], [1, 10]]→[1, 2, 3, 7, 7, 8, 9, 10]. The two 7s both appear; the 10 waits until every other list is drained.lists = [[5], [], [4, 6]]→[4, 5, 6]. An empty list in the middle contributes nothing and must not break the merge.lists = []→[]. No lists at all.
Hints
- Merging two sorted lists is easy. What goes wrong if you merge list 1 into list 2, then the result into list 3, and so on?
- At every step the next output node is the smallest of the
kcurrent heads. Which structure gives you "smallest of k things" and lets you replace one of them cheaply? - A min-heap of
(value, tiebreaker, node)with one entry per non-empty list; pop the min, append it, push its successor. Alternatively, merge pairs of lists in a tournament (divide and conquer).
Last reviewed 8 September 2026
Locked
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Secure payment by Stripe · instant access · refund questions: [email protected]
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.