LeetCode 21 ·
Easy
Merge Two Sorted Lists
Merge two sorted linked lists into one sorted list.
Try it
Step through the core mechanic. The simulator below runs the linked list shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is Linked list — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
A dummy head plus a tail pointer. Repeatedly splice whichever input head is smaller; attach the leftover tail at the end. The dummy avoids special-casing the first node.
| Aspect | Value |
|---|---|
| Pattern | Linked list |
| Recognise it by | Two-pointer merge of sorted lists. |
| Time complexity | O(n+m) |
| Space complexity | O(1) |
| Difficulty | Easy |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.