Given an array of n+1 integers where each integer is between 1 and n, find the duplicate number. Must not modify the array and use only O(1) extra space.
Treat array as a linked list with cycle (Floyd's algorithm). Index i points to nums[i]. The duplicate creates a cycle. Find the cycle start.
- Use slow = nums[nums[slow]] and fast = nums[fast] (like linked list).
- Find intersection point inside cycle.
- Then use two slow pointers from start and intersection to find cycle entrance (= duplicate).
- Time Complexity: O(N)
- Space Complexity: O(1)