Medium · 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
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.