dsa · easy

Linked List Cycle II (start)

GreyOrangeLinked ListTwo PointersFoundation

head is node values, pos is the index the tail links back to (-1 = no cycle). Reconstruct the list and return the **index where the cycle starts**, or -1.

Arguments

**Example:** head=[3,2,0,-4], pos=11.

Constraints

0 <= len(head) <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[3,2,0,-4]
1

Expected:
1

Example 2

Input:
[1,2]
-1

Expected:
-1

Open in the Dojo editor