Contains Duplicate
Recognize the pattern
Brute force idea
The naive version of Contains Duplicate sounds like this: Compare every pair of elements with nested loops. That direct path helps you understand the question, but it tends to treat every possibility as brand new instead of learning from earlier steps.
Better approach
The deeper shift in Contains Duplicate is this: Add each element to a set; if it's already there, you found a duplicate. 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 Contains Duplicate is one steady idea: The set contains every unique element seen so far. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.
Watch out for
The trap in Contains Duplicate usually looks like this: Sorting can solve the problem, but it answers a bigger question than the prompt is really asking. If all you need is to know whether you have seen a value before, a set gives you that answer much more directly. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.