Hash Table LeetCode Problems: All 588, With Python Solutions
Every problem in this library that LeetCode tags Hash Table — 588 in total, 492 of them with a complete Python solution, a worked example and the time and space complexity of the approach.
- 588 problems
- 143 Easy
- 347 Medium
- 98 Hard
How Hash Table problems are solved
A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Hash Table problems — each one explains the approach, gives a Python template and states its complexity.
- Hash Map — Trade memory for time: remember what you have seen so the second pass never happens.
Hash Table problems by difficulty
Showing the first 200 of 588 problems. Problems with a complete Python solution are listed first, then by ascending problem number.
Easy (47)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 1 | Two Sum | Easy | Array, Hash Table |
| 13 | Roman to Integer | Easy | Hash Table, Math, String |
| 141 | Linked List Cycle | Easy | Hash Table, Linked List, Two Pointers |
| 160 | Intersection of Two Linked Lists | Easy | Hash Table, Linked List, Two Pointers |
| 169 | Majority Element | Easy | Array, Hash Table, Divide and Conquer +2 |
| 202 | Happy Number | Easy | Hash Table, Math, Two Pointers |
| 205 | Isomorphic Strings | Easy | Hash Table, String |
| 217 | Contains Duplicate | Easy | Array, Hash Table, Sorting |
| 219 | Contains Duplicate II | Easy | Array, Hash Table, Sliding Window |
| 242 | Valid Anagram | Easy | Hash Table, String, Sorting |
| 268 | Missing Number | Easy | Bit Manipulation, Array, Hash Table +3 |
| 290 | Word Pattern | Easy | Hash Table, String |
| 349 | Intersection of Two Arrays | Easy | Array, Hash Table, Two Pointers +2 |
| 350 | Intersection of Two Arrays II | Easy | Array, Hash Table, Two Pointers +2 |
| 383 | Ransom Note | Easy | Hash Table, String, Counting |
| 387 | First Unique Character in a String | Easy | Queue, Hash Table, String +1 |
| 389 | Find the Difference | Easy | Bit Manipulation, Hash Table, String +1 |
| 409 | Longest Palindrome | Easy | Greedy, Hash Table, String |
| 448 | Find All Numbers Disappeared in an Array | Easy | Array, Hash Table |
| 496 | Next Greater Element I | Easy | Stack, Array, Hash Table +1 |
| 500 | Keyboard Row | Easy | Array, Hash Table, String |
| 575 | Distribute Candies | Easy | Array, Hash Table |
| 594 | Longest Harmonious Subsequence | Easy | Array, Hash Table, Counting +2 |
| 599 | Minimum Index Sum of Two Lists | Easy | Array, Hash Table, String |
| 645 | Set Mismatch | Easy | Bit Manipulation, Array, Hash Table +1 |
| 653 | Two Sum IV - Input is a BST | Easy | Tree, Depth-First Search, Breadth-First Search +4 |
| 697 | Degree of an Array | Easy | Array, Hash Table |
| 705 | Design HashSet | Easy | Design, Array, Hash Table +2 |
| 706 | Design HashMap | Easy | Design, Array, Hash Table +2 |
| 748 | Shortest Completing Word | Easy | Array, Hash Table, String |
| 771 | Jewels and Stones | Easy | Hash Table, String |
| 804 | Unique Morse Code Words | Easy | Array, Hash Table, String |
| 819 | Most Common Word | Easy | Array, Hash Table, String +1 |
| 859 | Buddy Strings | Easy | Hash Table, String |
| 884 | Uncommon Words from Two Sentences | Easy | Hash Table, String, Counting |
| 888 | Fair Candy Swap | Easy | Array, Hash Table, Binary Search +1 |
| 914 | X of a Kind in a Deck of Cards | Easy | Array, Hash Table, Math +2 |
| 929 | Unique Email Addresses | Easy | Array, Hash Table, String |
| 953 | Verifying an Alien Dictionary | Easy | Array, Hash Table, String |
| 961 | N-Repeated Element in Size 2N Array | Easy | Array, Hash Table |
| 997 | Find the Town Judge | Easy | Graph, Array, Hash Table |
| 1002 | Find Common Characters | Easy | Array, Hash Table, String |
| 1122 | Relative Sort Array | Easy | Array, Hash Table, Counting Sort +1 |
| 1128 | Number of Equivalent Domino Pairs | Easy | Array, Hash Table, Counting |
| 1160 | Find Words That Can Be Formed by Characters | Easy | Array, Hash Table, String +1 |
| 1189 | Maximum Number of Balloons | Easy | Hash Table, String, Counting |
| 1207 | Unique Number of Occurrences | Easy | Array, Hash Table |
Medium (115)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 3 | Longest Substring Without Repeating Characters | Medium | Hash Table, String, Sliding Window |
| 12 | Integer to Roman | Medium | Hash Table, Math, String |
| 17 | Letter Combinations of a Phone Number | Medium | Hash Table, String, Backtracking |
| 36 | Valid Sudoku | Medium | Array, Hash Table, Matrix |
| 49 | Group Anagrams | Medium | Array, Hash Table, String +1 |
| 73 | Set Matrix Zeroes | Medium | Array, Hash Table, Matrix |
| 105 | Construct Binary Tree from Preorder and Inorder Traversal | Medium | Tree, Array, Hash Table +2 |
| 106 | Construct Binary Tree from Inorder and Postorder Traversal | Medium | Tree, Array, Hash Table +2 |
| 128 | Longest Consecutive Sequence | Medium | Union Find, Array, Hash Table |
| 133 | Clone Graph | Medium | Depth-First Search, Breadth-First Search, Graph +1 |
| 138 | Copy List with Random Pointer | Medium | Hash Table, Linked List |
| 139 | Word Break | Medium | Trie, Memoization, Array +3 |
| 142 | Linked List Cycle II | Medium | Hash Table, Linked List, Two Pointers |
| 146 | LRU Cache | Medium | Design, Hash Table, Linked List +1 |
| 166 | Fraction to Recurring Decimal | Medium | Hash Table, Math, String |
| 187 | Repeated DNA Sequences | Medium | Bit Manipulation, Hash Table, String +3 |
| 208 | Implement Trie (Prefix Tree) | Medium | Design, Trie, Hash Table +1 |
| 229 | Majority Element II | Medium | Array, Hash Table, Counting +1 |
| 264 | Ugly Number II | Medium | Hash Table, Math, Dynamic Programming +1 |
| 299 | Bulls and Cows | Medium | Hash Table, String, Counting |
| 347 | Top K Frequent Elements | Medium | Array, Hash Table, Divide and Conquer +5 |
| 355 | Design Twitter | Medium | Design, Hash Table, Linked List +1 |
| 380 | Insert Delete GetRandom O(1) | Medium | Design, Array, Hash Table +2 |
| 395 | Longest Substring with At Least K Repeating Characters | Medium | Hash Table, String, Divide and Conquer +1 |
| 398 | Random Pick Index | Medium | Reservoir Sampling, Hash Table, Math +1 |
| 421 | Maximum XOR of Two Numbers in an Array | Medium | Bit Manipulation, Trie, Array +1 |
| 423 | Reconstruct Original Digits from English | Medium | Hash Table, Math, String |
| 424 | Longest Repeating Character Replacement | Medium | Hash Table, String, Sliding Window |
| 433 | Minimum Genetic Mutation | Medium | Breadth-First Search, Hash Table, String |
| 438 | Find All Anagrams in a String | Medium | Hash Table, String, Sliding Window |
| 442 | Find All Duplicates in an Array | Medium | Array, Hash Table, Sorting |
| 447 | Number of Boomerangs | Medium | Array, Hash Table, Math |
| 451 | Sort Characters By Frequency | Medium | Hash Table, String, Bucket Sort +3 |
| 454 | 4Sum II | Medium | Array, Hash Table |
| 457 | Circular Array Loop | Medium | Array, Hash Table, Two Pointers |
| 491 | Non-decreasing Subsequences | Medium | Bit Manipulation, Array, Hash Table +1 |
| 508 | Most Frequent Subtree Sum | Medium | Tree, Depth-First Search, Hash Table +1 |
| 519 | Random Flip Matrix | Medium | Reservoir Sampling, Hash Table, Math +1 |
| 522 | Longest Uncommon Subsequence II | Medium | Array, Hash Table, Two Pointers +2 |
| 523 | Continuous Subarray Sum | Medium | Array, Hash Table, Math +1 |
| 525 | Contiguous Array | Medium | Array, Hash Table, Prefix Sum |
| 532 | K-diff Pairs in an Array | Medium | Array, Hash Table, Two Pointers +2 |
| 535 | Encode and Decode TinyURL | Medium | Design, Hash Table, String +1 |
| 554 | Brick Wall | Medium | Array, Hash Table |
| 560 | Subarray Sum Equals K | Medium | Array, Hash Table, Prefix Sum |
| 567 | Permutation in String | Medium | Hash Table, Two Pointers, String +1 |
| 609 | Find Duplicate File in System | Medium | Array, Hash Table, String |
| 621 | Task Scheduler | Medium | Greedy, Array, Hash Table +3 |
| 648 | Replace Words | Medium | Trie, Array, Hash Table +1 |
| 652 | Find Duplicate Subtrees | Medium | Tree, Depth-First Search, Hash Table +1 |
| 659 | Split Array into Consecutive Subsequences | Medium | Greedy, Array, Hash Table +1 |
| 676 | Implement Magic Dictionary | Medium | Depth-First Search, Design, Trie +2 |
| 677 | Map Sum Pairs | Medium | Design, Trie, Hash Table +1 |
| 690 | Employee Importance | Medium | Tree, Depth-First Search, Breadth-First Search +2 |
| 692 | Top K Frequent Words | Medium | Trie, Array, Hash Table +5 |
| 720 | Longest Word in Dictionary | Medium | Trie, Array, Hash Table +2 |
| 721 | Accounts Merge | Medium | Depth-First Search, Breadth-First Search, Union Find +4 |
| 740 | Delete and Earn | Medium | Array, Hash Table, Dynamic Programming |
| 752 | Open the Lock | Medium | Breadth-First Search, Array, Hash Table +1 |
| 756 | Pyramid Transition Matrix | Medium | Bit Manipulation, Hash Table, String +1 |
| 763 | Partition Labels | Medium | Greedy, Hash Table, Two Pointers +1 |
| 767 | Reorganize String | Medium | Greedy, Hash Table, String +3 |
| 781 | Rabbits in Forest | Medium | Greedy, Array, Hash Table +1 |
| 791 | Custom Sort String | Medium | Hash Table, String, Sorting |
| 792 | Number of Matching Subsequences | Medium | Trie, Array, Hash Table +4 |
| 811 | Subdomain Visit Count | Medium | Array, Hash Table, String +1 |
| 817 | Linked List Components | Medium | Array, Hash Table, Linked List |
| 820 | Short Encoding of Words | Medium | Trie, Array, Hash Table +1 |
| 822 | Card Flipping Game | Medium | Array, Hash Table |
| 823 | Binary Trees With Factors | Medium | Array, Hash Table, Dynamic Programming +1 |
| 833 | Find And Replace in String | Medium | Array, Hash Table, String +1 |
| 840 | Magic Squares In Grid | Medium | Array, Hash Table, Math +1 |
| 846 | Hand of Straights | Medium | Greedy, Array, Hash Table +1 |
| 863 | All Nodes Distance K in Binary Tree | Medium | Tree, Depth-First Search, Breadth-First Search +2 |
| 865 | Smallest Subtree with all the Deepest Nodes | Medium | Tree, Depth-First Search, Breadth-First Search +2 |
| 869 | Reordered Power of 2 | Medium | Hash Table, Math, Counting +2 |
| 873 | Length of Longest Fibonacci Subsequence | Medium | Array, Hash Table, Dynamic Programming |
| 874 | Walking Robot Simulation | Medium | Array, Hash Table, Simulation |
| 889 | Construct Binary Tree from Preorder and Postorder Traversal | Medium | Tree, Array, Hash Table +2 |
| 890 | Find and Replace Pattern | Medium | Array, Hash Table, String |
| 893 | Groups of Special-Equivalent Strings | Medium | Array, Hash Table, String +1 |
| 904 | Fruit Into Baskets | Medium | Array, Hash Table, Sliding Window |
| 911 | Online Election | Medium | Design, Array, Hash Table +1 |
| 916 | Word Subsets | Medium | Array, Hash Table, String |
| 923 | 3Sum With Multiplicity | Medium | Array, Hash Table, Two Pointers +2 |
| 930 | Binary Subarrays With Sum | Medium | Array, Hash Table, Prefix Sum +1 |
| 939 | Minimum Area Rectangle | Medium | Geometry, Array, Hash Table +2 |
| 947 | Most Stones Removed with Same Row or Column | Medium | Depth-First Search, Union Find, Graph +1 |
| 954 | Array of Doubled Pairs | Medium | Greedy, Array, Hash Table +1 |
| 959 | Regions Cut By Slashes | Medium | Depth-First Search, Breadth-First Search, Union Find +3 |
| 963 | Minimum Area Rectangle II | Medium | Geometry, Array, Hash Table +1 |
| 966 | Vowel Spellchecker | Medium | Array, Hash Table, String |
| 970 | Powerful Integers | Medium | Hash Table, Math, Enumeration |
| 974 | Subarray Sums Divisible by K | Medium | Array, Hash Table, Prefix Sum |
| 981 | Time Based Key-Value Store | Medium | Design, Hash Table, String +1 |
| 1010 | Pairs of Songs With Total Durations Divisible by 60 | Medium | Array, Hash Table, Counting |
| 1015 | Smallest Integer Divisible by K | Medium | Hash Table, Math |
| 1016 | Binary String With Substrings Representing 1 To N | Medium | Bit Manipulation, Hash Table, String +1 |
| 1027 | Longest Arithmetic Subsequence | Medium | Array, Hash Table, Binary Search +1 |
| 1048 | Longest String Chain | Medium | Array, Hash Table, Two Pointers +3 |
| 1054 | Distant Barcodes | Medium | Greedy, Array, Hash Table +3 |
| 1072 | Flip Columns For Maximum Number of Equal Rows | Medium | Array, Hash Table, Matrix |
| 1079 | Letter Tile Possibilities | Medium | Hash Table, String, Backtracking +1 |
| 1090 | Largest Values From Labels | Medium | Greedy, Array, Hash Table +2 |
| 1110 | Delete Nodes And Return Forest | Medium | Tree, Depth-First Search, Array +2 |
| 1123 | Lowest Common Ancestor of Deepest Leaves | Medium | Tree, Depth-First Search, Breadth-First Search +2 |
| 1124 | Longest Well-Performing Interval | Medium | Stack, Array, Hash Table +2 |
| 1138 | Alphabet Board Path | Medium | Hash Table, String |
| 1146 | Snapshot Array | Medium | Design, Array, Hash Table +1 |
| 1156 | Swap For Longest Repeated Character Substring | Medium | Hash Table, String, Sliding Window |
| 1169 | Invalid Transactions | Medium | Array, Hash Table, String +1 |
| 1170 | Compare Strings by Frequency of the Smallest Character | Medium | Array, Hash Table, String +2 |
| 1171 | Remove Zero Sum Consecutive Nodes from Linked List | Medium | Hash Table, Linked List |
| 1177 | Can Make Palindrome from Substring | Medium | Bit Manipulation, Array, Hash Table +2 |
| 1202 | Smallest String With Swaps | Medium | Depth-First Search, Breadth-First Search, Union Find +4 |
Hard (38)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 30 | Substring with Concatenation of All Words | Hard | Hash Table, String, Sliding Window |
| 37 | Sudoku Solver | Hard | Array, Hash Table, Backtracking +1 |
| 41 | First Missing Positive | Hard | Array, Hash Table |
| 76 | Minimum Window Substring | Hard | Hash Table, String, Sliding Window |
| 126 | Word Ladder II | Hard | Breadth-First Search, Hash Table, String +1 |
| 127 | Word Ladder | Hard | Breadth-First Search, Hash Table, String |
| 140 | Word Break II | Hard | Trie, Memoization, Array +4 |
| 149 | Max Points on a Line | Hard | Geometry, Array, Hash Table +1 |
| 336 | Palindrome Pairs | Hard | Trie, Array, Hash Table +1 |
| 352 | Data Stream as Disjoint Intervals | Hard | Union Find, Design, Hash Table +3 |
| 381 | Insert Delete GetRandom O(1) - Duplicates allowed | Hard | Design, Array, Hash Table +2 |
| 391 | Perfect Rectangle | Hard | Geometry, Array, Hash Table +2 |
| 432 | All O`one Data Structure | Hard | Design, Hash Table, Linked List +1 |
| 460 | LFU Cache | Hard | Design, Hash Table, Linked List +1 |
| 480 | Sliding Window Median | Hard | Array, Hash Table, Sliding Window +1 |
| 632 | Smallest Range Covering Elements from K Lists | Hard | Greedy, Array, Hash Table +3 |
| 691 | Stickers to Spell Word | Hard | Bit Manipulation, Memoization, Array +5 |
| 710 | Random Pick with Blacklist | Hard | Array, Hash Table, Math +3 |
| 736 | Parse Lisp Expression | Hard | Stack, Recursion, Hash Table +1 |
| 745 | Prefix and Suffix Search | Hard | Design, Trie, Array +2 |
| 815 | Bus Routes | Hard | Breadth-First Search, Array, Hash Table |
| 828 | Count Unique Characters of All Substrings of a Given String | Hard | Hash Table, String, Dynamic Programming |
| 839 | Similar String Groups | Hard | Depth-First Search, Breadth-First Search, Union Find +3 |
| 854 | K-Similar Strings | Hard | Breadth-First Search, Hash Table, String |
| 895 | Maximum Frequency Stack | Hard | Stack, Design, Hash Table +1 |
| 924 | Minimize Malware Spread | Hard | Depth-First Search, Breadth-First Search, Union Find +3 |
| 928 | Minimize Malware Spread II | Hard | Depth-First Search, Breadth-First Search, Union Find +3 |
| 952 | Largest Component Size by Common Factor | Hard | Union Find, Array, Hash Table +2 |
| 982 | Triples with Bitwise AND Equal To Zero | Hard | Bit Manipulation, Array, Hash Table |
| 987 | Vertical Order Traversal of a Binary Tree | Hard | Tree, Depth-First Search, Breadth-First Search +3 |
| 992 | Subarrays with K Different Integers | Hard | Array, Hash Table, Counting +1 |
| 996 | Number of Squareful Arrays | Hard | Bit Manipulation, Array, Hash Table +4 |
| 1001 | Grid Illumination | Hard | Array, Hash Table |
| 1036 | Escape a Large Maze | Hard | Depth-First Search, Breadth-First Search, Array +1 |
| 1074 | Number of Submatrices That Sum to Target | Hard | Array, Hash Table, Matrix +1 |
| 1096 | Brace Expansion II | Hard | Stack, Breadth-First Search, Hash Table +3 |
| 1172 | Dinner Plate Stacks | Hard | Stack, Design, Hash Table +1 |
| 1178 | Number of Valid Words for Each Puzzle | Hard | Bit Manipulation, Trie, Array +2 |
Keep exploring
- Array1,569
- String672
- Math485
- Dynamic Programming481
- Sorting392
- Greedy346
- Depth-First Search289
- Binary Search253
- Database249
- Tree225
- Breadth-First Search223
- Matrix216
- Two Pointers201
- Bit Manipulation194
- Binary Tree174
- Heap (Priority Queue)163
- Prefix Sum157
- Stack157
- Simulation144
- Graph138
- Counting126
- Design122
- Sliding Window116
- Backtracking105
When the Hash Table problem arrives live
Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.