Skip to content
nalar

Part 2 · Module 4

Hash map: count and look up

Use Map and Set to count frequencies, find duplicates, check anagrams, and solve two sum in one pass.

4 lessons · 47 min in total

When to reach for it

Count with a Map
When a problem asks "how many times", "most often", "appears once", or "same number of".
A Set for "seen it before"
When a problem mentions duplicates, unique, repeated, or "appears again".
Count up, count down
When two collections must hold the same items in any order. Anagrams, building from letters, or comparing inventories.
Look up the partner in a map
When a problem looks for two items that match (a sum, a difference, a pair) and O(n²) brute force is too slow.