We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
Most easy and medium array problems collapse the moment you put the right thing in a hash map: a value you have already seen, a count, or an index. The pattern is less about the data structure than the habit of asking what single lookup would make the brute-force loop unnecessary. Start here - it is the foundation nearly every other pattern builds on.
"Have I seen this before?", counting occurrences, or an O(n²) scan you want to make O(n).
49 problems. Each one runs in an in-browser editor against real test cases, with hints and a worked solution.
The patterns cheat sheet covers all of these in one page - what each one looks like in a problem statement, and the template that follows.