Start Learning
Javaneer
Back to roadmap
🗝️
Stage 3

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.

5 Lessons in this stage1 h 9 min
Start the first lesson

Lessons in this stage

  1. 01

    How Hashing Works

    Intermediate

    Hash functions, buckets, collisions, and why HashMap operations are O(1) on average but O(n) in the worst case.

    15 min
  2. 02

    Counting & Frequency

    Intermediate

    Frequency maps solve a startling range of problems - first unique, majority element, top-k - in a single pass.

    13 min
  3. 03

    Grouping & De-duplication

    Intermediate

    Map<K, List<V>> to group by a computed key, and sets to dedupe or detect 'seen before' in O(1).

    13 min
  4. 04

    The Complement Trick

    Intermediate

    The single most common hashing pattern: remember what you've seen so each element's partner is an O(1) lookup away.

    12 min
  5. 05

    Designing an LRU Cache

    Advanced

    A 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