86. Find Where a Cycle Begins
MediumLinked lists
Return the 0-based index of the node where a cycle in the linked list begins, or -1 if the list has no cycle. Use O(1) extra memory.
The tests write the list as { values, pos }: the tail links to the node at index pos, or to nothing when pos is -1. Your function only receives the head.
Example 1
Input: values = [3, 2, 0, -4], pos = 1 Output: 1
Constraints
0 ≤ nodes ≤ 10⁴