Hash Maps
Trade a little memory for O(1) answers to "have I seen this before?"
5 lessons · ~47 min · free
By the end you can
- Replace nested-loop searches with one-pass dictionary lookups
- Count frequencies and compare them for anagram-style problems
- Use the seen-before pattern for duplicates and pair sums
- Combine prefix sums with a hash map to count subarrays hitting a target
- Tell hash map problems apart from sorting and window problems
Lessons
- 1The lookup you repeat a million times8 minWhere the pattern comes from: nested scans that keep re-asking the same question a dict answers instantly.
- 2Counting things9 minFrequency maps: anagrams, majority elements, and the Counter habits that make them one-liners.
- 3The seen-before pattern10 minDuplicates, complements, and two-sum done properly: check the map before you add to it.
- 4Prefix sums plus a hash map12 minSubarray sum equals k: running totals and the "how often have I seen sum minus k" trick.
- 5Spotting hash map problems8 minPairs, counts, and uniqueness cues; where dicts lose to sorting; the templates side by side.
Practice it after
Real interview questions that test this pattern, in an editor with execution and AI feedback.