Optimal Algorithmic Approach
Index-as-hash: mark visited positions by negating; a second visit to an already-negative slot reveals the duplicate.
Core Invariants & Edge Cases
- Use array indices as a hash — negate nums[abs(nums[i])-1]
- If already negative when you visit, that index+1 is a duplicate
- Works only when values are in [1, n]