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
head— the linked list, given as a Python list of node valuespos— 0-based index the tail links back to, or-1if there is no cycle
**Example:** head=[3,2,0,-4], pos=1 → 1.
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