Roadmap › Stage 1: Foundations (Start Here) › Pattern 3 of 53
DSA pattern guide
Hashing — Basics
"Have I seen this before?", counting things, or finding a matching pair fast.
Use it when
"Have I seen this before?", counting things, or finding a matching pair fast.
Key idea
A HashMap/HashSet gives O(1) lookups, so one pass with a map replaces a nested loop. Store what you've seen, and check for the complement as you go.
Practise it right here
3 original problems for this pattern in our free in-browser console. Write Java, Python or JavaScript and get an instant verdict, no install needed.
Open the practice consolePractice problems, in order
- Two SumEasy
- Contains DuplicateEasy
- Valid AnagramEasy
- Ransom NoteEasy
- First Unique Character in a StringEasy
- Intersection of Two ArraysEasy
- Group AnagramsMedium
- Longest Consecutive SequenceMedium
How to practise this pattern
- Read the problem and look for the signal above before writing any code.
- Say the brute force out loud, with its time complexity, then ask what work it repeats.
- Apply the key idea and write the optimised version yourself.
- If you're stuck for more than 10 minutes, take one small hint, not the full solution.
- Move to the next problem only when you can explain why this pattern fits.
Stuck on one of these?
The AlgoSolveo extension (free, launching soon) sits beside the LeetCode problem and gives the smallest hint that gets you moving, never the full answer. Solved problems tick off on your roadmap.
Join the extension waitlistTrack it on the roadmap