Find the Intersection Node of Two Linked Lists
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Bloomberg OA reported in November 2019 hands you a node table where next[i] is -1 when a chain ends, and asks for the first index both heads can reach. It's the classic linked list intersection problem dressed in array clothing. Identity matters, not values, and that's the whole trap. Example 3 even starts both heads at node 0. If you've seen the two-pointer swap trick, this is five minutes. If you blank, StealthCoder is the invisible safety net on the live OA that reads the problem and hands you a working solution.
The problem
Two acyclic singly linked lists are stored in one node table. Node i points to node next[i]; a value of -1 means that the node has no successor. The integers headA and headB are the head-node indices, or -1 for an empty list. Return the index of the first node that is reachable from both heads. Intersection is based on node identity, not equal values. Once the lists reach the same node, they share the remaining suffix. Return -1 if they do not intersect. Function findIntersectionNode(next: int[], headA: int, headB: int) → int Examples Example 1 next = [1,2,3,-1,2] headA = 0 headB = 4 return = 2 The first list follows 0 -> 1 -> 2 -> 3, while the second follows 4 -> 2 -> 3. Their first shared node is index 2. Example 2 next = [1,-1,3,-1] headA = 0 headB = 2 return = -1 The two chains end separately, so there is no shared node. Example 3 next = [1,2,-1] headA = 0 headB = 0 return = 0 Both lists start at the same node, so that head is the intersection. Constraints 0 <= next.length <= 200000 Every entry of next is -1 or a valid node index. Each chain reachable from headA or headB is acyclic. Each head is -1 or a valid node index.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is two pointers that switch lists. Start pa at headA and pb at headB. Each step, move to next[p]. When a pointer hits -1, restart it at the other list's head. Both pointers walk lenA + lenB nodes total, so they line up and meet at the intersection, or both land on -1 together if there's none. Pitfalls: comparing next values instead of indices, forgetting that headA or headB can be -1, and looping forever because you never let both reach -1. Check pa != pb in the loop, and make the switch happen only once per pointer. A hash set of visited indices from list A also works in O(n) space, and it's a fine fallback. If you freeze under the clock, StealthCoder can cover you during the live OA, but the pointer swap is short enough to memorize tonight.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Find the Intersection Node of Two Linked Lists cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as intersection of two linked lists. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find the Intersection Node of Two Linked Lists FAQ
What's the trick for the Bloomberg intersection node problem?+
Use two pointers that swap to the other list's head when they fall off the end. Both traverse lenA + lenB steps, so they meet at the first shared node. If there's no intersection, both reach -1 at the same moment and you return -1.
Can I just use a hash set?+
Yes. Walk list A and store every index in a set, then walk list B and return the first index already in the set. It's O(n) time and O(n) space. It passes the constraints, so it's a safe fallback if you can't recall the two-pointer version.
What edge cases break this problem?+
Empty lists where headA or headB is -1, both heads being the same node as in Example 3, and disjoint chains like Example 2. Also a shared node that is the last node. Compare indices, never values, since equal values don't mean a shared node.
How hard is this really?+
Easy. The input format looks unusual, but it's the standard intersection of two linked lists problem. The only real work is translating pointer moves into next[p] lookups and handling -1 correctly. Most people finish it quickly once they spot the pattern.
How do I prepare in 48 hours?+
Write the two-pointer swap from scratch twice using the next array, and test it on all three examples. Then write the hash set version as a backup. Trace the no-intersection case by hand so you trust the termination condition.