Hash maps and hash sets for O(1) lookups. Essential for frequency counting and two-sum type problems.
Time
Insert/Search/Delete: O(1) average, O(n) worst
Space
O(n)
Problems
4 must-do
| # | Problem | Difficulty | Asked At |
|---|---|---|---|
| 1 | Two Sum | Easy | Google Amazon Microsoft |
| 2 | Group Anagrams | Medium | Google Amazon Meta |
| 3 | Subarray Sum Equals K | Medium | Google Meta Amazon |
| 4 | LRU Cache | Hard | Google Amazon Microsoft |
HashMap: key-value pairs. HashSet: unique values only
Hash collision handling: chaining (linked list) or open addressing
In Python, use defaultdict for cleaner code
Prefix sum + HashMap is a powerful pattern for subarray problems