Single Number
Recognize the pattern
Brute force idea
If you approach Single Number in the most literal way possible, you get this: Use a hash set to track seen elements. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.
Better approach
The real unlock in Single Number comes when you notice this: XOR all elements — duplicates cancel out, leaving the unique one. Instead of recomputing the world every time, you preserve just enough context to let the next decision become obvious.
Key invariant
The compass for Single Number is this: a XOR a = 0 and a XOR 0 = a, so XOR of all elements eliminates pairs. As long as that statement keeps holding, you can trust the steps built on top of it.
Watch out for
A common way to get lost in Single Number is this: Not knowing the XOR trick — this is a classic bit manipulation insight. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.