FastPrepFind a Linked-List Intersection by Identity
Problems/Find a Linked-List Intersection by Identity

Find a Linked-List Intersection by Identity

AMD logoAMD● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the intersection of two linked lists. Node-identity semantics, null/disjoint behavior and a shared next-index serialization are explicit authored completion; approximate source match90%.

Two singly linked lists are represented by node identities0..n-1 and a shared link table next. Entry next[i] is the identity of node i successor, or-1 for null. The heads may reach the same tail nodes. Return the identity of their first shared node, or-1 if they are disjoint. Identity, not an equal payload value, establishes intersection. Leave all links unchanged; unused table entries do not affect the answer.

Function

intersectionNode(next: int[], headA: int, headB: int) → int

Examples

Example 1

next = [2,3,4,4,-1]headA = 0headB = 1return = 4

The paths are0→2→4 and1→3→4, so their first common identity is4.

Example 2

next = [1,-1,3,-1]headA = 0headB = 2return = -1

The paths0→1 and2→3 contain no shared node identity.

Constraints

  • 0 <= next.length <= 500.
  • -1 <= next[i] <= 499.
  • -1 <= headA <= 499.
  • -1 <= headB <= 499.
  • Every next entry and head is either -1 or a node index less than next.length; following links from either head reaches -1 without a cycle.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public int intersectionNode(int[] next, int headA, int headB) {
    // Write your code here.
}
Checking account…