Intersection of Two Linked Lists
Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.

30:00

Intersection of Two Linked Lists
easy
Topics
Companies

Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.

Example 1:
Input: {"listA":[4,1,8,4,5],"listB":[5,6,1,8,4,5],"skipA":2,"skipB":3}
Output: [8,4,5]
Constraints:
  • The number of nodes of listA is in the range [1,3×104][1, 3 \times 10^4].

  • The number of nodes of listB is in the range [1,3×104][1, 3 \times 10^4].

  • 1Node.val1051 \leq \text{Node.val} \leq 10^5

  • 0skipAm0 \leq \text{skipA} \leq m

  • 0skipBn0 \leq \text{skipB} \leq n

  • If the two lists intersect, then intersectVal == listA[skipA] == listB[skipB].

Input
arr ={"listA":[4,1,8,4,5],"listB":[5,6,1,8,4,5],"skipA":2,"skipB":3}

Find intersection of two linked lists. A length: 5, B length: 6

Pointer A
Pointer B
Intersection
List A (length: 5)
A

4

A[0]

1

A[1]

8

A[2]

4

A[3]

5

A[4]

null

List B (length: 6)
B

5

B[0]

6

B[1]

1

B[2]

8

B[3]

4

B[4]

5

B[5]

null

Skip A: 2, Skip B: 3 | Intersection at value: 8

Variables
No variables to display
DepthFunction Call
Stack empty
0/16