The Intersection of Two Linked Lists interview question asks you to find the node at which two singly linked lists merge. If the two lists have no common intersection point, return null. The lists are guaranteed to have no cycles, and you must return the original node itself, not just its value.
Companies like Microsoft, Meta, and Adobe use this to test a candidate's mastery of Pointer Manipulation. It evaluations whether you can synchronize two pointers moving at different speeds or starting from different distances. It’s a classic Linked List interview pattern that rewards mathematical observation over complex algorithms.
The most elegant solution uses the Two Pointers (Switching Heads) pattern.
pA at the head of List A and pB at the head of List B.pA reaches the end of List A, redirect it to the head of List B. When pB reaches the end of List B, redirect it to the head of List A.length(A) + length(B) steps, they are guaranteed to meet at the intersection point or both reach null simultaneously.List A: [a1, a2, c1, c2, c3], List B: [b1, b2, b3, c1, c2, c3].
a1, a2, c1, c2, c3, null, b1, b2, b3, c1. (10 steps)b1, b2, b3, c1, c2, c3, null, a1, a2, c1. (10 steps)c1 at exactly the same time.The "Switching Heads" trick is a beautiful way to equalize distances. It’s a recurring theme in Two Pointers interview patterns where you need to coordinate two independent sequences.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Linked List Cycle | Easy | Solve | |
| Linked List Cycle II | Medium | Solve | |
| Middle of the Linked List | Easy | Solve | |
| Remove Nth Node From End of List | Medium | Solve | |
| Remove Duplicates from Sorted List II | Medium | Solve |