Hashing & Sets
The O(1) lookup behind most fast solutions.
Hashing turns a huge class of O(n^2) problems into O(n): counting, grouping, de-duplication, and the complement trick. Understand how a hash map works under the hood, then use it to design something real - an LRU cache.
Lessons in this stage
- 01
How Hashing Works
IntermediateHash functions, buckets, collisions, and why HashMap operations are O(1) on average but O(n) in the worst case.
15 min - 02
Counting & Frequency
IntermediateFrequency maps solve a startling range of problems - first unique, majority element, top-k - in a single pass.
13 min - 03
Grouping & De-duplication
IntermediateMap<K, List<V>> to group by a computed key, and sets to dedupe or detect 'seen before' in O(1).
13 min - 04
The Complement Trick
IntermediateThe single most common hashing pattern: remember what you've seen so each element's partner is an O(1) lookup away.
12 min - 05
Designing an LRU Cache
AdvancedA classic design question: combine a hash map with a doubly linked list to get O(1) get and put with least-recently-used eviction.
16 min