Medium · Linked Lists

Linked List Cycle II

Given the head of a singly linked list, return the node where its cycle begins (the first node that following next pointers reaches twice), or null if the list has no cycle. In the samples, loopAt is the 0-based index the tail links back to, or −1 when the tail ends in null.

Examples

Example 1

[1,2,3,4,5] ↺ idx 1

Output: loop entry @ 1 (val 2)

Example 2

[1,2,3,4] no loop

Output: no loop

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Linked Lists problems