Linked List Intersection Finder - Problem
Given two singly linked lists that may merge at some point, find the intersection node where they first converge.
If the two linked lists have no intersection at all, return null.
The linked lists must retain their original structure after the function returns.
You may assume there are no cycles anywhere in the entire linked structure.
Each value on each node is in the range [1, 109].
Input & Output
Example 1 — Lists Intersect at Node 4
$
Input:
listA = [1,8,4], listB = [5,4], intersectVal = 4
›
Output:
4
💡 Note:
List A: 1→8→4, List B: 5→4. They intersect at the node with value 4. The intersection node is where the linked lists merge, not just matching values.
Example 2 — No Intersection
$
Input:
listA = [2,6,4], listB = [1,5], intersectVal = null
›
Output:
null
💡 Note:
The two linked lists do not intersect at all, so return null. Even if they had the same values, they would need to share actual node references.
Example 3 — Intersection at Head
$
Input:
listA = [3], listB = [3], intersectVal = 3
›
Output:
3
💡 Note:
Both lists consist of the same single node, so they intersect at the head node with value 3.
Constraints
-
The number of nodes of listA is in the range
[0, 3 × 104] -
The number of nodes of listB is in the range
[0, 3 × 104] -
1 ≤ Node.val ≤ 105 -
0 ≤ skipA ≤ m -
0 ≤ skipB ≤ n
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code