Linked List Cycle II

Find where the cycle begins.

Problem: Find where a linked list cycle begins.

Approach: 1.1. Fast/slow pointers find meeting point in cycle.

2.2. Reset one to head, move both at same speed.

3.3. They meet at cycle start.

Math: Fast travels a+b+ca + b + c, slow travels a+ba + b. Since 2(a+b)=a+b+c2(a+b) = a+b+c, we get a=cba = c - b. From meeting point, cbc-b steps reaches cycle start, same as aa steps from head.

Time: O(n)O(n). Space: O(1)O(1).