Intersection of Two Linked Lists Problem

Intersection of Two Linked Lists Problem — ExecCode Easy DSA Practice

Solve the Intersection of Two Linked Lists problem on ExecCode. Free online easy DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given the heads of two singly linked lists that may intersect, return the node at which they intersect, or null if they do not.

Examples

Input listA = [4, 1, 8, 4, 5], listB = [5, 6, 1, 8, 4, 5], skipA = 2, skipB = 3; Output 8. Input listA = [1, 9, 1, 2, 4], listB = [3, 2, 4], skipA = 3, skipB = 1; Output 2. Input listA = [2, 6, 4], listB = [1, 5], skipA = 3, skipB = 2; Output 0

Constraints

list lengths sum ≤ 3×10⁴ 1 ≤ Node.val ≤ 10⁵ The intersected shared portion has identical node references, not just equal values.

Practice Intersection of Two Linked Lists free on ExecCode. Browse DSA problems, topic map, and placement guides.