Find the Duplicate Number
Recognize the pattern
Brute force idea
A straightforward first read of Find the Duplicate Number is this: Sort and scan, or hash set but that costs extra memory. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
Better approach
The deeper shift in Find the Duplicate Number is this: Floyd's cycle detection: treat the array as a linked list where index i points to nums[i]. The duplicate creates a cycle. Use slow/fast pointers to find the cycle entry point. Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.
Key invariant
At the center of Find the Duplicate Number is one steady idea: Since there are n+1 values in range [1,n], the pigeonhole principle guarantees a duplicate. The duplicate value creates a cycle in the index-following graph — Floyd's algorithm finds the cycle entry. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.
Watch out for
A common way to get lost in Find the Duplicate Number is this: Not seeing the linked list analogy — arr[i] is the 'next' pointer. Starting from index 0, following these pointers eventually enters a cycle, and the cycle entry point is the duplicate. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.