Skip to content
StackDecode
Linked listsExplained

Intersection of Two Linked Lists

Walk both lists, switching heads at the end, so the pointers meet at the intersection.

Time

O(n + m)

Extra space

O(1)

Use it for

Finding a shared tail.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.