16. Hashing
HashMap and HashSet patterns: counting, grouping and prefix-sum maps.
π¬ Episodes 37β39: video coming soon
Your progress0 of 12
6easy
5medium
1hard
Understand the topic
A HashMap stores key β value pairs, and a HashSet stores keys, both with O(1) average lookup. Inside, the key's hashCode picks a bucket; collisions go into a chain (Java turns long chains into trees).
The common patterns are: "have I seen this before?" (a set), "how many of each?" (a count map), "where did I see it?" (a value β index map), and "group by a canonical key". Remember that arrays used as keys compare by reference, so convert them to a String or List first.
| # | Problem | Pattern | Level | ||
|---|---|---|---|---|---|
| 1 | Two Sum #1 | HashMap complement lookup | Easy | LeetCode β | |
| 2 | Contains Duplicate #217 | HashSet | Easy | LeetCode β | |
| 3 | Intersection of Two Arrays #349 | HashSet | Easy | LeetCode β | |
| 4 | Word Pattern #290 | Two-way HashMap | Easy | LeetCode β | |
| 5 | Unique Number of Occurrences #1207 | HashMap + HashSet | Easy | LeetCode β | |
| 6 | Happy Number #202 | HashSet cycle detection | Easy | LeetCode β | |
| 7 | Longest Consecutive Sequence #128 | HashSet, start only at run starts | Medium | LeetCode β | |
| 8 | 4Sum II #454 | Meet in the middle with HashMap | Medium | LeetCode β | |
| 9 | Max Number of K-Sum Pairs #1679 | HashMap pairing | Medium | LeetCode β | |
| 10 | Brick Wall #554 | HashMap of edge positions | Medium | LeetCode β | |
| 11 | Equal Row and Column Pairs #2352 | HashMap of row signatures | Medium | LeetCode β | |
| 12 | Max Points on a Line #149 | HashMap of reduced slopes | Hard | LeetCode β |
Nothing matches that filter.
Work top to bottom β each list goes from easy to hard. Try a problem for at least 15 minutes before opening a hint. Ticks are saved in your browser.