Linked List Cycle II
Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.

30:00

Linked List Cycle II
medium
Topics
Companies

Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.

Example 1:
Input: {"values":[3,2,0,-4],"cyclePos":1}
Output: [2,0,-4]
Constraints:
  • The number of nodes is in the range [0,104][0, 10^4].

  • 105Node.val105-10^5 \leq \text{Node.val} \leq 10^5

  • pos\text{pos} is 1-1 or a valid index in the linked list.

Input
arr ={"values":[3,2,0,-4],"cyclePos":1}

Find cycle start. List has cycle at index 1

Phase 1: Detect

Phase 2: Find Start

Linked List (cycle at index 1)
3

S

F

0

2

1

0

2

-4

3

↩ to [1]

Slow (S)
Fast (F)
Both Meet
Cycle Start
Variables
No variables to display
DepthFunction Call
Stack empty
0/7