LC 21
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.

AspectValue
PatternLinked list
Recognise it byTwo-pointer merge of sorted lists.
Time complexityO(n+m)
Space complexityO(1)
DifficultyEasy

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.