Hash Table Problems for Coding Interviews

A hash table trades memory for speed: constant-time lookups turn many quadratic solutions into linear ones. The classic uses are counting frequencies, finding a complement (two sum), grouping by a key and detecting duplicates or cycles.

When a brute-force solution compares every pair, ask whether remembering what you have already seen would let you answer in one pass. Practise choosing the right key, handling collisions in your explanation and bounding the memory you use.

Coding problems

Related

Frequently asked questions

How do I get good at hash table problems?

Solve a few problems of each difficulty, name the pattern after you solve each one, and revisit the ones you needed hints for a week later. The list on this page is ordered so you can start with the basic ones.

Can I run hash table problems online here?

Yes. Every problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and six more languages, with no setup.