Easy · Linked Lists

Find Intersection of Two Lists

Given the heads of two singly linked lists, return the node where they merge (the first node reachable from both heads), or null if they share no node. In the samples, list A is prefixA followed by shared and list B is prefixB followed by the same physical shared tail.

Examples

Example 1

A=[3,7] B=[9] tail=[8,4,5]

Output: intersection @ 8

Example 2

A=[2,6] B=[1] tail=[] (disjoint)

Output: nil (disjoint)

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Linked Lists problems