Treat the array as a linked list where i -> nums[i]. The duplicate creates a cycle.
Use Floyd’s cycle detection:
With n+1 values in range 1..n, the mapping must repeat, forming a cycle whose entry corresponds to the duplicate.
Treat the array as a linked list where i -> nums[i]. The duplicate creates a cycle.
Use Floyd’s cycle detection:
With n+1 values in range 1..n, the mapping must repeat, forming a cycle whose entry corresponds to the duplicate.