Merge Two Sorted Lists
Problem
You are given the heads of two singly linked lists, each already sorted in non-decreasing order. Splice the nodes of the two lists together into a single sorted list and return its head. Reuse the existing nodes; do not create new ones.
- Each list has between 0 and 200 nodes.
- Node values fit in a signed 32-bit integer.
- Both lists are sorted in non-decreasing order.
Examples
l1 = 2 -> 5 -> 9,l2 = 3 -> 5 -> 11→2 -> 3 -> 5 -> 5 -> 9 -> 11. Equal values from both lists are both kept.l1 = empty,l2 = empty→empty.l1 = 7,l2 = empty→7. When one list is empty the other is already the answer.
Hints
- At each step, which of the two current heads must come next in the merged list?
- Building a list by appending requires a pointer to the current tail. What do you attach the very first node to?
- Use a dummy head node so the tail pointer always has something to append to, then attach whichever list is left over.
Last reviewed 8 September 2026
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.
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.