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
- Contains Duplicate (Basic)
- Climbing Stairs (Basic)
- First Unique Character (Basic)
- Kth Largest Element (Intermediate)
- Missing Number (Basic)
- Intersection of Two Arrays (Basic)
- Count Distinct Values (Basic)
- Valid Anagram (Basic)
- Remove Duplicates Keeping Order (Basic)
- Third Maximum Number (Basic)
- Unique Grid Paths (Intermediate)
- Search in a Rotated Sorted Array (Advanced)
- Minimum in a Rotated Sorted Array (Intermediate)
- Sum of Unique Values (Basic)
- Sort Characters by Frequency (Intermediate)
- Kth Missing Positive Number (Basic)
- Find the Duplicate and Missing Number (Basic)
- Minimum Deletions for Unique Frequencies (Intermediate)
- Unique Number of Occurrences (Basic)
- Find All Anagram Starts (Intermediate)
- Remove Adjacent Duplicate Letters (Basic)
- Array Frequency Analysis (Intermediate)
- Maximum Sum of Distinct Window (Intermediate)
- Count Unique Binary Search Trees (Basic)
- Count Numbers With Unique Digits (Intermediate)
- Maximum Frequency After Increments (Basic)
- Minimum Value in Bitonic Array (Intermediate)
- Smallest Number From Pattern (Intermediate)
- Minimum Height Trees (Intermediate)
- Lowest Common Ancestor With Parent Pointers (Intermediate)
- Tree Infection Time (Intermediate)
- Tree Nodes at Distance K (Advanced)
- Tree Distance Queries (Basic)
- Coin Change Ways (Intermediate)
- Largest Divisible Subset Size (Advanced)
- Minimum Swaps To Sort (Intermediate)
- Unique Paths With Obstacles (Intermediate)
- Deduplicate Sorted Linked List (Intermediate)
- BST Range Sum (Basic)
- Count Distinct Islands Shapes (Basic)
- Offline Distinct Range Queries (Intermediate)
- Count Substrings With Exactly K Distinct (Intermediate)
- BST Successor and Predecessor (Intermediate)
- Find Duplicate Subtrees (Basic)
- Maximum Path Quality (Basic)
- Maximum Sum Path Across Two Arrays (Basic)
- Find Intersection of Three Sorted Arrays (Intermediate)
- Count Range Frequency Queries (Intermediate)
- Search a Nearly Sorted Array (Intermediate)
- Randomized Set With Duplicates (Advanced)
- IP Longest Prefix Match (Advanced)
- Consistent Hash Ring (Intermediate)
- Kth Smallest Value in a BST (Intermediate)
- Lowest Common Ancestor of Two Values (Intermediate)
- Linked List Components (Intermediate)
- Element Frequencies in a Linked List (Basic)
- Tree From Preorder and Inorder (Intermediate)
- Tree From Inorder and Postorder (Intermediate)
- Minimum Absolute Difference in BST (Basic)
- Two Sum in a BST (Basic)
Related
- Sliding window problems
- Dynamic programming problems
- Graph problems
- Practice coding problems online
- All interview question topics
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.