Linked List Cycle Entry Node
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google, July 2026. The problem looks like a graph question, but it's a single path starting at node 0 with an array standing in for pointers. Follow next[i] until you hit -1 or land on a node you've already seen. That's the whole thing. It's Linked List Cycle II wearing an array costume, and the candidates who recognize it in the first minute have the rest of the OA to breathe. If you blank on the pointer trick under the clock, StealthCoder runs invisibly on your screen as a safety net and hands you the solution while you keep typing.
The problem
A singly linked list is serialized by an integer array next. Node i points to node next[i]; a value of -1 means that node has no successor. Node 0 is the head, and every represented node is reachable by repeatedly following successors from the head before traversal stops or repeats a node. If the list contains a cycle, return the zero-based index of the first node in that cycle. Otherwise, return -1. Function findCycleEntry(next: int[]) → int Examples Example 1 next = [1,2,3,1] return = 1 The traversal is 0 -> 1 -> 2 -> 3 -> 1. Node 1 is the first node in the cycle. Example 2 next = [1,2,3,-1] return = -1 The traversal reaches node 3 and then stops, so the list has no cycle. Example 3 next = [0] return = 0 The head points to itself, so node 0 is the cycle entry. Constraints 1 <= next.length <= 2 * 10^5. Every next[i] is either -1 or an integer from 0 through next.length - 1. Every represented node is reachable from node 0 before traversal stops or first repeats a node.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Every node has at most one outgoing edge, so the walk from node 0 is a single path that either ends at -1 or loops. Two clean approaches. First, a visited array: walk from 0, mark each index, and the first index you reach that's already marked is the cycle entry. That's O(n) time and O(n) space, and it's fine for 2 * 10^5. Second, Floyd's tortoise and hare: move slow one step and fast two, detect a meeting, then reset one pointer to 0 and advance both one step at a time until they meet. That meeting point is the entry, with O(1) space. Pitfalls: forgetting that fast can hit -1 mid-jump, and returning the meeting point from phase one instead of the entry. Example 3, next = [0], is the self-loop edge case. If Floyd's phase two slips your mind during the live OA, StealthCoder is the hedge, and the visited-array version is always your safe fallback.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Linked List Cycle Entry Node 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 by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as linked list cycle ii. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Linked List Cycle Entry Node FAQ
What's the trick for the Google linked list cycle entry problem?+
Treat next as pointers and walk from node 0. Either mark visited indices and return the first repeat, or use Floyd's two-pointer method to find a meeting point, then restart one pointer at 0 and step both by one. The second meeting is the entry.
How hard is this one really?+
Easy to medium. The logic is short, but the array encoding and the -1 terminator trip people up. If you've seen Linked List Cycle II, it's the same idea. If not, the visited-array version is simple enough to write in a few minutes.
Do I need Floyd's algorithm, or is a visited array fine?+
A visited array is fine. The constraint is 2 * 10^5, so O(n) extra memory is no problem. Floyd's only buys you O(1) space. Write the visited version first, get it passing, and only switch if you have time and want the cleaner space profile.
What edge cases should I test before submitting?+
Test next = [0], where the head loops to itself and the answer is 0. Test a single node with -1, which returns -1. Test a long chain with no cycle, and a cycle that returns to node 0. Also make sure fast never indexes with -1.
How do I prepare for this in 48 hours?+
Write both versions from memory once: the visited-array walk and Floyd's with the phase-two reset. Then run the three given examples by hand. That's enough. This pattern is small, so spend the rest of your time on other likely problem types for the OA.