O(1) key-value lookups, the backbone of frequency counting, grouping, and deduplication.
1 algorithm1 variant2 races7 problems
2 visualizers. Each one stands alone.
Same input, side by side. Watch who wins.
Why a hash map turns Two Sum into one pass, and what sorting first buys you.
Watch the raceWhy a hash set finds a repeat in one pass, and what sorting first buys you.
Watch the raceA hash map stores key and value pairs and finds a key in about the same time whether it holds ten entries or ten million. It sits under dictionaries in Python, objects and Map in JavaScript, HashMap in Java, database indexes and caches. In interviews it is the first tool to try when a brute force answer compares every pair. This section starts with the basic operations, then two pages on how a map works inside and two on putting it to use.
Turn the key into a slot number and go straight there. A hash function maps each key to an index, so a lookup checks one small place instead of scanning everything. Two keys can land on the same index, and the two build pages differ only in how they handle that clash. The two problem pages lean on that fast lookup to skip a sort or a nested loop.
If you are learning how maps work, read chaining before probing, since probing adds the tricky delete. If you are preparing for interviews, the two problem pages matter more. In Two Sum the order of lookup and insert is the usual slip: storing first lets a value pair with itself. Remember that O(1) is an average; a bad hash or an overfull table can make one lookup O(n).