Hash Map Pattern: Template + 709 LeetCode Problems

Trade memory for time: remember what you have seen so the second pass never happens.

  • 227 Easy
  • 372 Medium
  • 110 Hard
  • O(1) average per operation, O(n) worst case time

What the hash map pattern is

A hash map converts a search into a lookup, which is why it is the most common single answer in this entire corpus — 588 of the 3000 problems are built on one. Three uses cover nearly all of them. The complement lookup asks, at each element, whether the thing that would complete the answer has already been seen: storing values as you go turns two nested loops into one pass, and the reason it works is that a pair is found from its second member, so only the past needs to be remembered. Frequency counting answers anagram, majority and top-k questions by comparing counts instead of arrangements. Grouping needs a canonical key — a sorted string, a character-count tuple, a normalised pattern — chosen so that two inputs collide exactly when they belong together, and that choice is the whole problem. Python's dict preserves insertion order, so an ordered result often needs no extra bookkeeping.

When to use it

  • The brute force is a nested loop asking "is there another element such that…".
  • You are counting occurrences, or comparing two multisets.
  • Items must be grouped by a property you can compute into a stable key.
  • Membership must be tested repeatedly and the input is not sorted.
  • Seen-before state has to survive across a single pass — de-duplication, cycle detection on values.

The hash map template in Python

The shape, not a solution to any one problem. Adapt the condition and the summary being maintained; the skeleton stays the same across the 709 problems listed below.

Hash Map — Python template
def two_sum(nums, target):
    seen = {}                            # value -> the index it was found at

    for i, value in enumerate(nums):
        if target - value in seen:       # the partner was already scanned
            return [seen[target - value], i]
        seen[value] = i

    return []

Complexity characteristics

Time
O(1) average per operation, O(n) worst case
Auxiliary space
O(n)

Average-case constant lookups are what turn a nested-loop search into a single pass, so the complement and frequency-counting solutions are O(n) time and O(n) space. The worst case is linear per operation when every key collides, which is irrelevant on real data and is the reason a language's string hash is randomised per process. Ordering is not free: getting a sorted result out of a map costs the sort on top.

All 709 hash map LeetCode problems

Every problem in the library the hash map pattern applies to, grouped by LeetCode's own difficulty rating. 601 of the 709 carry a complete Python solution with a worked example and complexity analysis; the rest are listed for completeness, with the LeetCode Premium ones marked.

Related LeetCode topics

Easy (227)

#ProblemDifficultyTopics
1Two SumEasyArray, Hash Table
13Roman to IntegerEasyHash Table, Math, String
58Length of Last WordEasyString
141Linked List CycleEasyHash Table, Linked List, Two Pointers
160Intersection of Two Linked ListsEasyHash Table, Linked List, Two Pointers
169Majority ElementEasyArray, Hash Table, Divide and Conquer +2
202Happy NumberEasyHash Table, Math, Two Pointers
205Isomorphic StringsEasyHash Table, String
217Contains DuplicateEasyArray, Hash Table, Sorting
219Contains Duplicate IIEasyArray, Hash Table, Sliding Window
242Valid AnagramEasyHash Table, String, Sorting
268Missing NumberEasyBit Manipulation, Array, Hash Table +3
290Word PatternEasyHash Table, String
349Intersection of Two ArraysEasyArray, Hash Table, Two Pointers +2
350Intersection of Two Arrays IIEasyArray, Hash Table, Two Pointers +2
383Ransom NoteEasyHash Table, String, Counting
387First Unique Character in a StringEasyQueue, Hash Table, String +1
389Find the DifferenceEasyBit Manipulation, Hash Table, String +1
409Longest PalindromeEasyGreedy, Hash Table, String
434Number of Segments in a StringEasyString
448Find All Numbers Disappeared in an ArrayEasyArray, Hash Table
459Repeated Substring PatternEasyString, String Matching
482License Key FormattingEasyString
496Next Greater Element IEasyStack, Array, Hash Table +1
500Keyboard RowEasyArray, Hash Table, String
520Detect CapitalEasyString
521Longest Uncommon Subsequence IEasyString
551Student Attendance Record IEasyString
575Distribute CandiesEasyArray, Hash Table
594Longest Harmonious SubsequenceEasyArray, Hash Table, Counting +2
599Minimum Index Sum of Two ListsEasyArray, Hash Table, String
645Set MismatchEasyBit Manipulation, Array, Hash Table +1
653Two Sum IV - Input is a BSTEasyTree, Depth-First Search, Breadth-First Search +4
657Robot Return to OriginEasyString, Simulation
697Degree of an ArrayEasyArray, Hash Table
705Design HashSetEasyDesign, Array, Hash Table +2
706Design HashMapEasyDesign, Array, Hash Table +2
709To Lower CaseEasyString
748Shortest Completing WordEasyArray, Hash Table, String
1207Unique Number of OccurrencesEasyArray, Hash Table
2215Find the Difference of Two ArraysEasyArray, Hash Table
170Two Sum III - Data structure designPremiumEasyDesign, Array, Hash Table +2
243Shortest Word DistancePremiumEasyArray, String
246Strobogrammatic NumberPremiumEasyHash Table, Two Pointers, String
266Palindrome PermutationPremiumEasyBit Manipulation, Hash Table, String
293Flip GamePremiumEasyString
359Logger Rate LimiterPremiumEasyDesign, Hash Table, Data Stream
604Design Compressed String IteratorPremiumEasyDesign, Array, String +1
734Sentence SimilarityPremiumEasyArray, Hash Table, String
760Find Anagram MappingsPremiumEasyArray, Hash Table
771Jewels and StonesEasyHash Table, String
796Rotate StringEasyString, String Matching
804Unique Morse Code WordsEasyArray, Hash Table, String
806Number of Lines To Write StringEasyArray, String
819Most Common WordEasyArray, Hash Table, String +1
824Goat LatinEasyString
830Positions of Large GroupsEasyString
859Buddy StringsEasyHash Table, String
884Uncommon Words from Two SentencesEasyHash Table, String, Counting
888Fair Candy SwapEasyArray, Hash Table, Binary Search +1
914X of a Kind in a Deck of CardsEasyArray, Hash Table, Math +2
929Unique Email AddressesEasyArray, Hash Table, String
944Delete Columns to Make SortedEasyArray, String
953Verifying an Alien DictionaryEasyArray, Hash Table, String
961N-Repeated Element in Size 2N ArrayEasyArray, Hash Table
997Find the Town JudgeEasyGraph, Array, Hash Table
1002Find Common CharactersEasyArray, Hash Table, String
1078Occurrences After BigramEasyString
1086High FivePremiumEasyArray, Hash Table, Sorting +1
1108Defanging an IP AddressEasyString
1119Remove Vowels from a StringPremiumEasyString
1122Relative Sort ArrayEasyArray, Hash Table, Counting Sort +1
1128Number of Equivalent Domino PairsEasyArray, Hash Table, Counting
1133Largest Unique NumberPremiumEasyArray, Hash Table, Sorting
1160Find Words That Can Be Formed by CharactersEasyArray, Hash Table, String +1
1165Single-Row KeyboardPremiumEasyHash Table, String
1189Maximum Number of BalloonsEasyHash Table, String, Counting
1213Intersection of Three Sorted ArraysPremiumEasyArray, Hash Table, Binary Search +1
1221Split a String in Balanced StringsEasyGreedy, String, Counting
1275Find Winner on a Tic Tac Toe GameEasyArray, Hash Table, Matrix +1
1309Decrypt String from Alphabet to Integer MappingEasyString
1331Rank Transform of an ArrayEasyArray, Hash Table, Sorting
1346Check If N and Its Double ExistEasyArray, Hash Table, Two Pointers +2
1356Sort Integers by The Number of 1 BitsEasyBit Manipulation, Array, Counting +1
1365How Many Numbers Are Smaller Than the Current NumberEasyArray, Hash Table, Counting Sort +1
1370Increasing Decreasing StringEasyHash Table, String, Counting
1374Generate a String With Characters That Have Odd CountsEasyString
1394Find Lucky Integer in an ArrayEasyArray, Hash Table, Counting
1399Count Largest GroupEasyHash Table, Math
1408String Matching in an ArrayEasyArray, String, String Matching
1417Reformat The StringEasyString
1426Counting ElementsPremiumEasyArray, Hash Table
1436Destination CityEasyArray, Hash Table, String
1446Consecutive CharactersEasyString
1460Make Two Arrays Equal by Reversing SubarraysEasyArray, Hash Table, Sorting
1496Path CrossingEasyHash Table, String
1507Reformat DateEasyString
1512Number of Good PairsEasyArray, Hash Table, Math +1
1528Shuffle StringEasyArray, String
1556Thousand SeparatorEasyString
1576Replace All ?'s to Avoid Consecutive Repeating CharactersEasyString
1592Rearrange Spaces Between WordsEasyString
1603Design Parking SystemEasyDesign, Counting, Simulation
1624Largest Substring Between Two Equal CharactersEasyHash Table, String
1629Slowest KeyEasyArray, String
1636Sort Array by Increasing FrequencyEasyArray, Hash Table, Sorting
1640Check Array Formation Through ConcatenationEasyArray, Hash Table
1656Design an Ordered StreamEasyDesign, Array, Hash Table +1
1662Check If Two String Arrays are EquivalentEasyArray, String
1678Goal Parser InterpretationEasyString
1684Count the Number of Consistent StringsEasyBit Manipulation, Array, Hash Table +2
1694Reformat Phone NumberEasyString
1704Determine if String Halves Are AlikeEasyString, Counting
1742Maximum Number of Balls in a BoxEasyHash Table, Math, Counting
1748Sum of Unique ElementsEasyArray, Hash Table, Counting
1758Minimum Changes To Make Alternating Binary StringEasyString
1763Longest Nice SubstringEasyBit Manipulation, Hash Table, String +2
1773Count Items Matching a RuleEasyArray, String
1784Check if Binary String Has at Most One Segment of OnesEasyString
1790Check if One String Swap Can Make Strings EqualEasyHash Table, String, Counting
1796Second Largest Digit in a StringEasyHash Table, String
1805Number of Different Integers in a StringEasyHash Table, String
1816Truncate SentenceEasyArray, String
1832Check if the Sentence Is PangramEasyHash Table, String
1844Replace All Digits with CharactersEasyString
1854Maximum Population YearEasyArray, Counting, Prefix Sum
1869Longer Contiguous Segments of Ones than ZerosEasyString
1876Substrings of Size Three with Distinct CharactersEasyHash Table, String, Counting +1
1880Check if Word Equals Summation of Two WordsEasyString
1893Check if All the Integers in a Range Are CoveredEasyArray, Hash Table, Prefix Sum
1897Redistribute Characters to Make All Strings EqualEasyHash Table, String, Counting
1933Check if String Is Decomposable Into Value-Equal SubstringsPremiumEasyString
1935Maximum Number of Words You Can TypeEasyHash Table, String
1941Check if All Characters Have Equal Number of OccurrencesEasyHash Table, String, Counting
1945Sum of Digits of String After ConvertEasyString, Simulation
1957Delete Characters to Make Fancy StringEasyString
1967Number of Strings That Appear as Substrings in WordEasyArray, String
1995Count Special QuadrupletsEasyArray, Hash Table, Enumeration
2006Count Number of Pairs With Absolute Difference KEasyArray, Hash Table, Counting
2011Final Value of Variable After Performing OperationsEasyArray, String, Simulation
2032Two Out of ThreeEasyBit Manipulation, Array, Hash Table
2042Check if Numbers Are Ascending in a SentenceEasyString
2047Number of Valid Words in a SentenceEasyString
2053Kth Distinct String in an ArrayEasyArray, Hash Table, String +1
2062Count Vowel Substrings of a StringEasyHash Table, String
2068Check Whether Two Strings are Almost EquivalentEasyHash Table, String, Counting
2085Count Common Words With One OccurrenceEasyArray, Hash Table, String +1
2094Finding 3-Digit Even NumbersEasyRecursion, Array, Hash Table +2
2099Find Subsequence of Length K With the Largest SumEasyArray, Hash Table, Sorting +1
2103Rings and RodsEasyHash Table, String
2114Maximum Number of Words Found in SentencesEasyArray, String
2124Check if All A's Appears Before All B'sEasyString
2129Capitalize the TitleEasyString
2133Check if Every Row and Column Contains All NumbersEasyArray, Hash Table, Matrix
2138Divide a String Into Groups of Size kEasyString, Simulation
2148Count Elements With Strictly Smaller and Greater ElementsEasyArray, Counting, Sorting
2154Keep Multiplying Found Values by TwoEasyArray, Hash Table, Sorting +1
2185Counting Words With a Given PrefixEasyArray, String, String Matching
2190Most Frequent Number Following Key In an ArrayEasyArray, Hash Table, Counting
2194Cells in a Range on an Excel SheetEasyString
2206Divide Array Into Equal PairsEasyBit Manipulation, Array, Hash Table +1
2229Check if an Array Is ConsecutivePremiumEasyArray, Hash Table, Sorting
2243Calculate Digit Sum of a StringEasyString, Simulation
2248Intersection of Multiple ArraysEasyArray, Hash Table, Counting +1
2255Count Prefixes of a Given StringEasyArray, String
2264Largest 3-Same-Digit Number in StringEasyString
2273Find Resultant Array After Removing AnagramsEasyArray, Hash Table, String +1
2278Percentage of Letter in StringEasyString
2283Check if Number Has Equal Digit Count and Digit ValueEasyHash Table, String, Counting
2287Rearrange Characters to Make Target StringEasyHash Table, String, Counting
2299Strong Password Checker IIEasyString
2309Greatest English Letter in Upper and Lower CaseEasyHash Table, String, Enumeration
2315Count AsterisksEasyString
2325Decode the MessageEasyHash Table, String
2341Maximum Number of Pairs in ArrayEasyArray, Hash Table, Counting
2347Best Poker HandEasyArray, Hash Table, Counting
2351First Letter to Appear TwiceEasyBit Manipulation, Hash Table, String +1
2357Make Array Zero by Subtracting Equal AmountsEasyGreedy, Array, Hash Table +3
2363Merge Similar ItemsEasyArray, Hash Table, Ordered Set +1
2367Number of Arithmetic TripletsEasyArray, Hash Table, Two Pointers +1
2395Find Subarrays With Equal SumEasyArray, Hash Table
2399Check Distances Between Same LettersEasyArray, Hash Table, String
2404Most Frequent Even ElementEasyArray, Hash Table, Counting
2418Sort the PeopleEasyArray, Hash Table, String +1
2423Remove Letter To Equalize FrequencyEasyHash Table, String, Counting
2437Number of Valid Clock TimesEasyString, Enumeration
2441Largest Positive Integer That Exists With Its NegativeEasyArray, Hash Table, Two Pointers +1
2446Determine if Two Events Have ConflictEasyArray, String
2451Odd String DifferenceEasyArray, Hash Table, String
2465Number of Distinct AveragesEasyArray, Hash Table, Two Pointers +1
2475Number of Unequal Triplets in ArrayEasyArray, Hash Table, Sorting
2490Circular SentenceEasyString
2496Maximum Value of a String in an ArrayEasyArray, String
2506Count Pairs Of Similar StringsEasyBit Manipulation, Array, Hash Table +2
2515Shortest Distance to Target String in a Circular ArrayEasyArray, String
2529Maximum Count of Positive Integer and Negative IntegerEasyArray, Binary Search, Counting
2540Minimum Common ValueEasyArray, Hash Table, Two Pointers +1
2549Count Distinct Numbers on BoardEasyArray, Hash Table, Math +1
2570Merge Two 2D Arrays by Summing ValuesEasyArray, Hash Table, Two Pointers
2586Count the Number of Vowel Strings in RangeEasyArray, String, Counting
2605Form Smallest Number From Two Digit ArraysEasyArray, Hash Table, Enumeration
2609Find the Longest Balanced Substring of a Binary StringEasyString
2670Find the Distinct Difference ArrayEasyArray, Hash Table
2678Number of Senior CitizensEasyArray, String
2682Find the Losers of the Circular GameEasyArray, Hash Table, Simulation
2710Remove Trailing Zeros From a StringEasyString
2716Minimize String LengthEasyHash Table, String
2729Check if The Number is FascinatingEasyHash Table, Math
2744Find Maximum Number of String PairsEasyArray, Hash Table, String +1
2748Number of Beautiful PairsEasyArray, Hash Table, Math +2
2784Check if Array is GoodEasyArray, Hash Table, Sorting
2788Split Strings by SeparatorEasyArray, String
2810Faulty KeyboardEasyString, Simulation
2815Max Pair Sum in an ArrayEasyArray, Hash Table
2828Check if a String Is an Acronym of WordsEasyArray, String
2833Furthest Point From OriginEasyString, Counting
2839Check if Strings Can be Made Equal With Operations IEasyString
2848Points That Intersect With CarsEasyArray, Hash Table, Prefix Sum
2869Minimum Operations to Collect ElementsEasyBit Manipulation, Array, Hash Table
2913Subarrays Distinct Element Sum of Squares IEasyArray, Hash Table
2932Maximum Strong Pair XOR IEasyBit Manipulation, Trie, Array +2
2937Make Three Strings EqualEasyString
2942Find Words Containing CharacterEasyArray, String
2956Find Common Elements Between Two ArraysEasyArray, Hash Table
2960Count Tested Devices After Test OperationsEasyArray, Counting, Simulation
2965Find Missing and Repeated ValuesEasyArray, Hash Table, Math +1
2996Smallest Missing Integer Greater Than Sequential Prefix SumEasyArray, Hash Table, Sorting

Medium (372)

#ProblemDifficultyTopics
3Longest Substring Without Repeating CharactersMediumHash Table, String, Sliding Window
6Zigzag ConversionMediumString
8String to Integer (atoi)MediumString
12Integer to RomanMediumHash Table, Math, String
17Letter Combinations of a Phone NumberMediumHash Table, String, Backtracking
36Valid SudokuMediumArray, Hash Table, Matrix
38Count and SayMediumString
49Group AnagramsMediumArray, Hash Table, String +1
73Set Matrix ZeroesMediumArray, Hash Table, Matrix
105Construct Binary Tree from Preorder and Inorder TraversalMediumTree, Array, Hash Table +2
106Construct Binary Tree from Inorder and Postorder TraversalMediumTree, Array, Hash Table +2
128Longest Consecutive SequenceMediumUnion Find, Array, Hash Table
133Clone GraphMediumDepth-First Search, Breadth-First Search, Graph +1
138Copy List with Random PointerMediumHash Table, Linked List
139Word BreakMediumTrie, Memoization, Array +3
142Linked List Cycle IIMediumHash Table, Linked List, Two Pointers
146LRU CacheMediumDesign, Hash Table, Linked List +1
166Fraction to Recurring DecimalMediumHash Table, Math, String
187Repeated DNA SequencesMediumBit Manipulation, Hash Table, String +3
208Implement Trie (Prefix Tree)MediumDesign, Trie, Hash Table +1
229Majority Element IIMediumArray, Hash Table, Counting +1
264Ugly Number IIMediumHash Table, Math, Dynamic Programming +1
299Bulls and CowsMediumHash Table, String, Counting
347Top K Frequent ElementsMediumArray, Hash Table, Divide and Conquer +5
355Design TwitterMediumDesign, Hash Table, Linked List +1
380Insert Delete GetRandom O(1)MediumDesign, Array, Hash Table +2
395Longest Substring with At Least K Repeating CharactersMediumHash Table, String, Divide and Conquer +1
398Random Pick IndexMediumReservoir Sampling, Hash Table, Math +1
421Maximum XOR of Two Numbers in an ArrayMediumBit Manipulation, Trie, Array +1
423Reconstruct Original Digits from EnglishMediumHash Table, Math, String
424Longest Repeating Character ReplacementMediumHash Table, String, Sliding Window
433Minimum Genetic MutationMediumBreadth-First Search, Hash Table, String
438Find All Anagrams in a StringMediumHash Table, String, Sliding Window
442Find All Duplicates in an ArrayMediumArray, Hash Table, Sorting
447Number of BoomerangsMediumArray, Hash Table, Math
451Sort Characters By FrequencyMediumHash Table, String, Bucket Sort +3
4544Sum IIMediumArray, Hash Table
457Circular Array LoopMediumArray, Hash Table, Two Pointers
468Validate IP AddressMediumString
491Non-decreasing SubsequencesMediumBit Manipulation, Array, Hash Table +1
508Most Frequent Subtree SumMediumTree, Depth-First Search, Hash Table +1
519Random Flip MatrixMediumReservoir Sampling, Hash Table, Math +1
522Longest Uncommon Subsequence IIMediumArray, Hash Table, Two Pointers +2
523Continuous Subarray SumMediumArray, Hash Table, Math +1
525Contiguous ArrayMediumArray, Hash Table, Prefix Sum
532K-diff Pairs in an ArrayMediumArray, Hash Table, Two Pointers +2
535Encode and Decode TinyURLMediumDesign, Hash Table, String +1
554Brick WallMediumArray, Hash Table
560Subarray Sum Equals KMediumArray, Hash Table, Prefix Sum
567Permutation in StringMediumHash Table, Two Pointers, String +1
609Find Duplicate File in SystemMediumArray, Hash Table, String
621Task SchedulerMediumGreedy, Array, Hash Table +3
648Replace WordsMediumTrie, Array, Hash Table +1
652Find Duplicate SubtreesMediumTree, Depth-First Search, Hash Table +1
659Split Array into Consecutive SubsequencesMediumGreedy, Array, Hash Table +1
676Implement Magic DictionaryMediumDepth-First Search, Design, Trie +2
677Map Sum PairsMediumDesign, Trie, Hash Table +1
686Repeated String MatchMediumString, String Matching
690Employee ImportanceMediumTree, Depth-First Search, Breadth-First Search +2
692Top K Frequent WordsMediumTrie, Array, Hash Table +5
720Longest Word in DictionaryMediumTrie, Array, Hash Table +2
721Accounts MergeMediumDepth-First Search, Breadth-First Search, Union Find +4
722Remove CommentsMediumArray, String
740Delete and EarnMediumArray, Hash Table, Dynamic Programming
763Partition LabelsMediumGreedy, Hash Table, Two Pointers +1
846Hand of StraightsMediumGreedy, Array, Hash Table +1
981Time Based Key-Value StoreMediumDesign, Hash Table, String +1
1657Determine if Two Strings Are CloseMediumHash Table, String, Counting +1
1679Max Number of K-Sum PairsMediumArray, Hash Table, Two Pointers +1
2013Detect SquaresMediumDesign, Array, Hash Table +1
2336Smallest Number in Infinite SetMediumDesign, Hash Table, Ordered Set +1
2352Equal Row and Column PairsMediumArray, Hash Table, Matrix +1
159Longest Substring with At Most Two Distinct CharactersPremiumMediumHash Table, String, Sliding Window
244Shortest Word Distance IIPremiumMediumDesign, Array, Hash Table +2
245Shortest Word Distance IIIPremiumMediumArray, String
247Strobogrammatic Number IIPremiumMediumRecursion, Array, String
249Group Shifted StringsPremiumMediumArray, Hash Table, String
267Palindrome Permutation IIPremiumMediumHash Table, String, Backtracking
271Encode and Decode StringsPremiumMediumDesign, Array, String
288Unique Word AbbreviationPremiumMediumDesign, Array, Hash Table +1
291Word Pattern IIPremiumMediumHash Table, String, Backtracking
311Sparse Matrix MultiplicationPremiumMediumArray, Hash Table, Matrix
314Binary Tree Vertical Order TraversalPremiumMediumTree, Depth-First Search, Breadth-First Search +3
325Maximum Size Subarray Sum Equals kPremiumMediumArray, Hash Table, Prefix Sum
340Longest Substring with At Most K Distinct CharactersPremiumMediumHash Table, String, Sliding Window
348Design Tic-Tac-ToePremiumMediumDesign, Array, Hash Table +2
353Design Snake GamePremiumMediumDesign, Queue, Array +2
356Line ReflectionPremiumMediumArray, Hash Table, Math
379Design Phone DirectoryPremiumMediumDesign, Queue, Array +2
531Lonely Pixel IPremiumMediumArray, Hash Table, Matrix
533Lonely Pixel IIPremiumMediumArray, Hash Table, Matrix
544Output Contest MatchesPremiumMediumRecursion, String, Simulation
582Kill ProcessPremiumMediumTree, Depth-First Search, Breadth-First Search +2
616Add Bold Tag in StringPremiumMediumTrie, Array, Hash Table +2
635Design Log Storage SystemPremiumMediumDesign, Hash Table, String +1
666Path Sum IVPremiumMediumTree, Depth-First Search, Array +2
681Next Closest TimePremiumMediumHash Table, String, Backtracking +1
694Number of Distinct IslandsPremiumMediumDepth-First Search, Breadth-First Search, Union Find +2
737Sentence Similarity IIPremiumMediumDepth-First Search, Breadth-First Search, Union Find +3
752Open the LockMediumBreadth-First Search, Array, Hash Table +1
756Pyramid Transition MatrixMediumBit Manipulation, Hash Table, String +1
758Bold Words in StringPremiumMediumTrie, Array, Hash Table +2
767Reorganize StringMediumGreedy, Hash Table, String +3
781Rabbits in ForestMediumGreedy, Array, Hash Table +1
791Custom Sort StringMediumHash Table, String, Sorting
792Number of Matching SubsequencesMediumTrie, Array, Hash Table +4
811Subdomain Visit CountMediumArray, Hash Table, String +1
817Linked List ComponentsMediumArray, Hash Table, Linked List
820Short Encoding of WordsMediumTrie, Array, Hash Table +1
822Card Flipping GameMediumArray, Hash Table
823Binary Trees With FactorsMediumArray, Hash Table, Dynamic Programming +1
831Masking Personal InformationMediumString
833Find And Replace in StringMediumArray, Hash Table, String +1
840Magic Squares In GridMediumArray, Hash Table, Math +1
863All Nodes Distance K in Binary TreeMediumTree, Depth-First Search, Breadth-First Search +2
865Smallest Subtree with all the Deepest NodesMediumTree, Depth-First Search, Breadth-First Search +2
869Reordered Power of 2MediumHash Table, Math, Counting +2
873Length of Longest Fibonacci SubsequenceMediumArray, Hash Table, Dynamic Programming
874Walking Robot SimulationMediumArray, Hash Table, Simulation
889Construct Binary Tree from Preorder and Postorder TraversalMediumTree, Array, Hash Table +2
890Find and Replace PatternMediumArray, Hash Table, String
893Groups of Special-Equivalent StringsMediumArray, Hash Table, String +1
900RLE IteratorMediumDesign, Array, Counting +1
904Fruit Into BasketsMediumArray, Hash Table, Sliding Window
911Online ElectionMediumDesign, Array, Hash Table +1
916Word SubsetsMediumArray, Hash Table, String
9233Sum With MultiplicityMediumArray, Hash Table, Two Pointers +2
930Binary Subarrays With SumMediumArray, Hash Table, Prefix Sum +1
939Minimum Area RectangleMediumGeometry, Array, Hash Table +2
945Minimum Increment to Make Array UniqueMediumGreedy, Array, Counting +1
947Most Stones Removed with Same Row or ColumnMediumDepth-First Search, Union Find, Graph +1
954Array of Doubled PairsMediumGreedy, Array, Hash Table +1
957Prison Cells After N DaysMediumBit Manipulation, Array, Hash Table +1
959Regions Cut By SlashesMediumDepth-First Search, Breadth-First Search, Union Find +3
963Minimum Area Rectangle IIMediumGeometry, Array, Hash Table +1
966Vowel SpellcheckerMediumArray, Hash Table, String
970Powerful IntegersMediumHash Table, Math, Enumeration
974Subarray Sums Divisible by KMediumArray, Hash Table, Prefix Sum
1010Pairs of Songs With Total Durations Divisible by 60MediumArray, Hash Table, Counting
1015Smallest Integer Divisible by KMediumHash Table, Math
1016Binary String With Substrings Representing 1 To NMediumBit Manipulation, Hash Table, String +1
1027Longest Arithmetic SubsequenceMediumArray, Hash Table, Binary Search +1
1048Longest String ChainMediumArray, Hash Table, Two Pointers +3
1054Distant BarcodesMediumGreedy, Array, Hash Table +3
1072Flip Columns For Maximum Number of Equal RowsMediumArray, Hash Table, Matrix
1079Letter Tile PossibilitiesMediumHash Table, String, Backtracking +1
1090Largest Values From LabelsMediumGreedy, Array, Hash Table +2
1100Find K-Length Substrings With No Repeated CharactersPremiumMediumHash Table, String, Sliding Window
1110Delete Nodes And Return ForestMediumTree, Depth-First Search, Array +2
1123Lowest Common Ancestor of Deepest LeavesMediumTree, Depth-First Search, Breadth-First Search +2
1124Longest Well-Performing IntervalMediumStack, Array, Hash Table +2
1138Alphabet Board PathMediumHash Table, String
1146Snapshot ArrayMediumDesign, Array, Hash Table +1
1152Analyze User Website Visit PatternPremiumMediumArray, Hash Table, String +1
1156Swap For Longest Repeated Character SubstringMediumHash Table, String, Sliding Window
1166Design File SystemPremiumMediumDesign, Trie, Hash Table +1
1169Invalid TransactionsMediumArray, Hash Table, String +1
1170Compare Strings by Frequency of the Smallest CharacterMediumArray, Hash Table, String +2
1171Remove Zero Sum Consecutive Nodes from Linked ListMediumHash Table, Linked List
1177Can Make Palindrome from SubstringMediumBit Manipulation, Array, Hash Table +2
1181Before and After PuzzlePremiumMediumArray, Hash Table, String +1
1198Find Smallest Common Element in All RowsPremiumMediumArray, Hash Table, Binary Search +2
1202Smallest String With SwapsMediumDepth-First Search, Breadth-First Search, Union Find +4
1218Longest Arithmetic Subsequence of Given DifferenceMediumArray, Hash Table, Dynamic Programming
1244Design A LeaderboardPremiumMediumDesign, Hash Table, Sorting
1248Count Number of Nice SubarraysMediumArray, Hash Table, Math +2
1257Smallest Common RegionPremiumMediumTree, Depth-First Search, Breadth-First Search +3
1258Synonymous SentencesPremiumMediumSort, Union Find, Array +3
1261Find Elements in a Contaminated Binary TreeMediumTree, Depth-First Search, Breadth-First Search +3
1267Count Servers that CommunicateMediumDepth-First Search, Breadth-First Search, Union Find +3
1282Group the People Given the Group Size They Belong ToMediumGreedy, Array, Hash Table
1296Divide Array in Sets of K Consecutive NumbersMediumGreedy, Array, Hash Table +1
1297Maximum Number of Occurrences of a SubstringMediumHash Table, String, Sliding Window
1311Get Watched Videos by Your FriendsMediumBreadth-First Search, Graph, Array +2
1324Print Words VerticallyMediumArray, String, Simulation
1338Reduce Array Size to The HalfMediumGreedy, Array, Hash Table +2
1347Minimum Number of Steps to Make Two Strings AnagramMediumHash Table, String, Counting
1348Tweet Counts Per FrequencyMediumDesign, Hash Table, String +3
1357Apply Discount Every n OrdersMediumDesign, Array, Hash Table
1358Number of Substrings Containing All Three CharactersMediumHash Table, String, Sliding Window
1366Rank Teams by VotesMediumArray, Hash Table, String +2
1371Find the Longest Substring Containing Vowels in Even CountsMediumBit Manipulation, Hash Table, String +1
1386Cinema Seat AllocationMediumGreedy, Bit Manipulation, Array +1
1396Design Underground SystemMediumDesign, Hash Table, String
1400Construct K Palindrome StringsMediumGreedy, Hash Table, String +1
1410HTML Entity ParserMediumHash Table, String
1418Display Table of Food Orders in a RestaurantMediumArray, Hash Table, String +2
1419Minimum Number of Frogs CroakingMediumString, Counting
1429First Unique NumberPremiumMediumDesign, Queue, Array +2
1442Count Triplets That Can Form Two Arrays of Equal XORMediumBit Manipulation, Array, Hash Table +2
1443Minimum Time to Collect All Apples in a TreeMediumTree, Depth-First Search, Breadth-First Search +1
1452People Whose List of Favorite Companies Is Not a Subset of Another ListMediumArray, Hash Table, String
1461Check If a String Contains All Binary Codes of Size KMediumBit Manipulation, Hash Table, String +2
1477Find Two Non-overlapping Sub-arrays Each With Target SumMediumArray, Hash Table, Binary Search +2
1481Least Number of Unique Integers after K RemovalsMediumGreedy, Array, Hash Table +2
1485Clone Binary Tree With Random PointerPremiumMediumTree, Depth-First Search, Breadth-First Search +2
1487Making File Names UniqueMediumArray, Hash Table, String
1488Avoid Flood in The CityMediumGreedy, Array, Hash Table +2
1490Clone N-ary TreePremiumMediumTree, Depth-First Search, Breadth-First Search +1
1497Check If Array Pairs Are Divisible by kMediumArray, Hash Table, Counting
1500Design a File Sharing SystemPremiumMediumDesign, Hash Table, Data Stream +2
1506Find Root of N-Ary TreePremiumMediumBit Manipulation, Tree, Depth-First Search +1
1519Number of Nodes in the Sub-Tree With the Same LabelMediumTree, Depth-First Search, Breadth-First Search +2
1525Number of Good Ways to Split a StringMediumBit Manipulation, Hash Table, String +1
1540Can Convert String in K MovesMediumHash Table, String
1545Find Kth Bit in Nth Binary StringMediumRecursion, String, Simulation
1546Maximum Number of Non-Overlapping Subarrays With Sum Equals TargetMediumGreedy, Array, Hash Table +1
1554Strings Differ by One CharacterPremiumMediumHash Table, String, Hash Function +1
1562Find Latest Group of Size MMediumArray, Hash Table, Binary Search +1
1570Dot Product of Two Sparse VectorsPremiumMediumDesign, Array, Hash Table +1
1577Number of Ways Where Square of Number Is Equal to Product of Two NumbersMediumArray, Hash Table, Math +1
1590Make Sum Divisible by PMediumArray, Hash Table, Prefix Sum
1593Split a String Into the Max Number of Unique SubstringsMediumHash Table, String, Backtracking
1600Throne InheritanceMediumTree, Depth-First Search, Design +1
1604Alert Using Same Key-Card Three or More Times in a One Hour PeriodMediumArray, Hash Table, String +1
1612Check If Two Expression Trees are EquivalentPremiumMediumTree, Depth-First Search, Hash Table +2
1630Arithmetic SubarraysMediumArray, Hash Table, Sorting
1638Count Substrings That Differ by One CharacterMediumHash Table, String, Dynamic Programming +1
1647Minimum Deletions to Make Character Frequencies UniqueMediumGreedy, Hash Table, String +1
1650Lowest Common Ancestor of a Binary Tree IIIPremiumMediumTree, Hash Table, Two Pointers +1
1658Minimum Operations to Reduce X to ZeroMediumArray, Hash Table, Binary Search +2
1660Correct a Binary TreePremiumMediumTree, Depth-First Search, Breadth-First Search +2
1674Minimum Moves to Make Array ComplementaryMediumArray, Hash Table, Prefix Sum
1676Lowest Common Ancestor of a Binary Tree IVPremiumMediumTree, Depth-First Search, Hash Table +1
1695Maximum Erasure ValueMediumArray, Hash Table, Sliding Window
1711Count Good MealsMediumArray, Hash Table
1726Tuple with Same ProductMediumArray, Hash Table, Counting
1733Minimum Number of People to TeachMediumGreedy, Array, Hash Table
1737Change Minimum Characters to Satisfy One of Three ConditionsMediumHash Table, String, Counting +1
1740Find Distance in a Binary TreePremiumMediumTree, Depth-First Search, Breadth-First Search +2
1743Restore the Array From Adjacent PairsMediumDepth-First Search, Array, Hash Table
1772Sort Features by PopularityPremiumMediumArray, Hash Table, String +1
1775Equal Sum Arrays With Minimum Number of OperationsMediumGreedy, Array, Hash Table +1
1781Sum of Beauty of All SubstringsMediumHash Table, String, Counting
1794Count Pairs of Equal Substrings With Minimum DifferencePremiumMediumGreedy, Hash Table, String
1797Design Authentication ManagerMediumDesign, Hash Table, Linked List +1
1804Implement Trie II (Prefix Tree)PremiumMediumDesign, Trie, Hash Table +1
1807Evaluate the Bracket Pairs of a StringMediumArray, Hash Table, String
1814Count Nice Pairs in an ArrayMediumArray, Hash Table, Math +1
1817Finding the Users Active MinutesMediumArray, Hash Table
1836Remove Duplicates From an Unsorted Linked ListPremiumMediumHash Table, Linked List
1852Distinct Numbers in Each SubarrayPremiumMediumArray, Hash Table, Sliding Window
1865Finding Pairs With a Certain SumMediumDesign, Array, Hash Table
1906Minimum Absolute Difference QueriesMediumArray, Hash Table
1915Number of Wonderful SubstringsMediumBit Manipulation, Hash Table, String +1
1930Unique Length-3 Palindromic SubsequencesMediumBit Manipulation, Hash Table, String +1
1940Longest Common Subsequence Between Sorted ArraysPremiumMediumArray, Hash Table, Counting
1942The Number of the Smallest Unoccupied ChairMediumArray, Hash Table, Heap (Priority Queue)
1943Describe the PaintingMediumArray, Hash Table, Prefix Sum +1
1980Find Unique Binary StringMediumArray, Hash Table, String +1
1983Widest Pair of Indices With Equal Range SumPremiumMediumArray, Hash Table, Prefix Sum
1993Operations on TreeMediumTree, Depth-First Search, Breadth-First Search +3
2001Number of Pairs of Interchangeable RectanglesMediumArray, Hash Table, Math +2
2007Find Original Array From Doubled ArrayMediumGreedy, Array, Hash Table +1
2008Maximum Earnings From TaxiMediumArray, Hash Table, Binary Search +2
2023Number of Pairs of Strings With Concatenation Equal to TargetMediumArray, Hash Table, String +1
2029Stone Game IXMediumGreedy, Array, Math +2
2031Count Subarrays With More Ones Than ZerosPremiumMediumBinary Indexed Tree, Segment Tree, Array +5
2034Stock Price FluctuationMediumDesign, Hash Table, Data Stream +2
2043Simple Bank SystemMediumDesign, Array, Hash Table +1
2048Next Greater Numerically Balanced NumberMediumHash Table, Math, Backtracking +2
2067Number of Equal Count SubstringsPremiumMediumHash Table, String, Counting +1
2075Decode the Slanted CiphertextMediumString, Simulation
2080Range Frequency QueriesMediumDesign, Segment Tree, Array +2
2083Substrings That Begin and End With the Same LetterPremiumMediumHash Table, Math, String +2
2107Number of Unique Flavors After Sharing K CandiesPremiumMediumArray, Hash Table, Sliding Window
2115Find All Possible Recipes from Given SuppliesMediumGraph, Topological Sort, Array +2
2120Execution of All Suffix Instructions Staying in a GridMediumString, Simulation
2121Intervals Between Identical ElementsMediumArray, Hash Table, Prefix Sum
2131Longest Palindrome by Concatenating Two Letter WordsMediumGreedy, Array, Hash Table +2
2135Count Words Obtained After Adding a LetterMediumBit Manipulation, Array, Hash Table +2
2150Find All Lonely Numbers in the ArrayMediumArray, Hash Table, Counting
2152Minimum Number of Lines to Cover PointsPremiumMediumBit Manipulation, Geometry, Array +5
2166Design BitsetMediumDesign, Array, Hash Table +1
2168Unique Substrings With Equal Digit FrequencyPremiumMediumHash Table, String, Counting +2
2170Minimum Operations to Make the Array AlternatingMediumGreedy, Array, Hash Table +1
2182Construct String With Repeat LimitMediumGreedy, Hash Table, String +2
2186Minimum Number of Steps to Make Two Strings Anagram IIMediumHash Table, String, Counting
2196Create Binary Tree From DescriptionsMediumTree, Array, Hash Table +1
2201Count Artifacts That Can Be ExtractedMediumArray, Hash Table, Simulation
2225Find Players With Zero or One LossesMediumArray, Hash Table, Counting +1
2232Minimize Result by Adding Parentheses to ExpressionMediumString, Enumeration
2244Minimum Rounds to Complete All TasksMediumGreedy, Array, Hash Table +1
2249Count Lattice Points Inside a CircleMediumGeometry, Array, Hash Table +2
2250Count Number of Rectangles Containing Each PointMediumBinary Indexed Tree, Array, Hash Table +2
2260Minimum Consecutive Cards to Pick UpMediumArray, Hash Table, Sliding Window
2261K Divisible Elements SubarraysMediumTrie, Array, Hash Table +3
2266Count Number of TextsMediumHash Table, Math, String +1
2268Minimum Number of KeypressesPremiumMediumGreedy, Hash Table, String +2
2275Largest Combination With Bitwise AND Greater Than ZeroMediumBit Manipulation, Array, Hash Table +1
2284Sender With Largest Word CountMediumArray, Hash Table, String +1
2288Apply Discount to PricesMediumString
2295Replace Elements in an ArrayMediumArray, Hash Table, Simulation
2342Max Sum of a Pair With Equal Sum of DigitsMediumArray, Hash Table, Sorting +1
2349Design a Number Container SystemMediumDesign, Hash Table, Ordered Set +1
2353Design a Food Rating SystemMediumDesign, Array, Hash Table +3
2364Count Number of Bad PairsMediumArray, Hash Table, Math +1
2365Task Scheduler IIMediumArray, Hash Table, Simulation
2368Reachable Nodes With RestrictionsMediumTree, Depth-First Search, Breadth-First Search +4
2370Longest Ideal SubsequenceMediumHash Table, String, Dynamic Programming
2374Node With Highest Edge ScoreMediumGraph, Hash Table
2384Largest Palindromic NumberMediumGreedy, Hash Table, String +1
2385Amount of Time for Binary Tree to Be InfectedMediumTree, Depth-First Search, Breadth-First Search +2
2405Optimal Partition of StringMediumGreedy, Hash Table, String
2408Design SQLPremiumMediumDesign, Array, Hash Table +1
2414Length of the Longest Alphabetical Continuous SubstringMediumString
2424Longest Uploaded PrefixMediumUnion Find, Design, Binary Indexed Tree +5
2434Using a Robot to Print the Lexicographically Smallest StringMediumStack, Greedy, Hash Table +1
2442Count Number of Distinct Integers After Reverse OperationsMediumArray, Hash Table, Math +1
2453Destroy Sequential TargetsMediumArray, Hash Table, Counting
2456Most Popular Video CreatorMediumArray, Hash Table, String +2
2461Maximum Sum of Distinct Subarrays With Length KMediumArray, Hash Table, Sliding Window
2489Number of Substrings With Fixed RatioPremiumMediumHash Table, Math, String +1
2491Divide Players Into Teams of Equal SkillMediumArray, Hash Table, Two Pointers +1
2501Longest Square Streak in an ArrayMediumArray, Hash Table, Binary Search +2
2502Design Memory AllocatorMediumDesign, Array, Hash Table +1
2512Reward Top K StudentsMediumArray, Hash Table, String +2
2516Take K of Each Character From Left and RightMediumHash Table, String, Sliding Window
2521Distinct Prime Factors of Product of ArrayMediumArray, Hash Table, Math +1
2526Find Consecutive Integers from a Data StreamMediumDesign, Queue, Hash Table +2
2531Make Number of Distinct Characters EqualMediumHash Table, String, Counting
2537Count the Number of Good SubarraysMediumArray, Hash Table, Sliding Window
2539Count the Number of Good SubsequencesPremiumMediumHash Table, Math, String +2
2554Maximum Number of Integers to Choose From a Range IMediumGreedy, Array, Hash Table +2
2564Substring XOR QueriesMediumBit Manipulation, Array, Hash Table +1
2588Count the Number of Beautiful SubarraysMediumBit Manipulation, Array, Hash Table +1
2590Design a Todo ListPremiumMediumDesign, Array, Hash Table +2
2593Find Score of an Array After Marking All ElementsMediumArray, Hash Table, Sorting +2
2597The Number of Beautiful SubsetsMediumArray, Hash Table, Math +4
2598Smallest Missing Non-negative Integer After OperationsMediumGreedy, Array, Hash Table +1
2606Find the Substring With Maximum CostMediumArray, Hash Table, String +1
2610Convert an Array Into a 2D Array With ConditionsMediumArray, Hash Table
2615Sum of DistancesMediumArray, Hash Table, Prefix Sum
2641Cousins in Binary Tree IIMediumTree, Depth-First Search, Breadth-First Search +2
2653Sliding Subarray BeautyMediumArray, Hash Table, Sliding Window
2657Find the Prefix Common Array of Two ArraysMediumBit Manipulation, Array, Hash Table
2661First Completely Painted Row or ColumnMediumArray, Hash Table, Matrix
2671Frequency TrackerMediumDesign, Hash Table
2707Extra Characters in a StringMediumTrie, Array, Hash Table +2
2711Difference of Number of Distinct Values on DiagonalsMediumArray, Hash Table, Matrix
2718Sum of Matrix After QueriesMediumArray, Hash Table
2743Count Substrings Without Repeating CharacterPremiumMediumHash Table, String, Sliding Window
2747Count Zero Request ServersMediumArray, Hash Table, Sorting +1
2766Relocate MarblesMediumArray, Hash Table, Sorting +1
2767Partition String Into Minimum Beautiful SubstringsMediumHash Table, String, Dynamic Programming +1
2768Number of Black BlocksMediumArray, Hash Table, Enumeration
2780Minimum Index of a Valid SplitMediumArray, Hash Table, Sorting
2782Number of Unique CategoriesPremiumMediumUnion Find, Counting, Interactive
2799Count Complete Subarrays in an ArrayMediumArray, Hash Table, Sliding Window
2808Minimum Seconds to Equalize a Circular ArrayMediumArray, Hash Table
2830Maximize the Profit as the SalesmanMediumArray, Hash Table, Binary Search +2
2831Find the Longest Equal SubarrayMediumArray, Hash Table, Binary Search +1
2840Check if Strings Can be Made Equal With Operations IIMediumHash Table, String, Sorting
2841Maximum Sum of Almost Unique SubarrayMediumArray, Hash Table, Sliding Window
2845Count of Interesting SubarraysMediumArray, Hash Table, Prefix Sum
2852Sum of Remoteness of All CellsPremiumMediumDepth-First Search, Breadth-First Search, Union Find +3
2856Minimum Array Length After Pair RemovalsMediumGreedy, Array, Hash Table +3
2857Count Pairs of Points With Distance kMediumBit Manipulation, Array, Hash Table
2870Minimum Number of Operations to Make Array EmptyMediumGreedy, Array, Hash Table +1
2875Minimum Size Subarray in Infinite ArrayMediumArray, Hash Table, Prefix Sum +1
2898Maximum Linear Stock ScorePremiumMediumArray, Hash Table
2910Minimum Number of Groups to Create a Valid AssignmentMediumGreedy, Array, Hash Table
2914Minimum Number of Changes to Make Binary String BeautifulMediumString
2933High-Access EmployeesMediumArray, Hash Table, String +1
2947Count Beautiful Substrings IMediumHash Table, Math, String +3
2950Number of Divisible SubstringsPremiumMediumHash Table, String, Counting +1
2955Number of Same-End SubstringsPremiumMediumArray, Hash Table, String +2
2958Length of Longest Subarray With at Most K FrequencyMediumArray, Hash Table, Sliding Window
2964Number of Divisible Triplet SumsPremiumMediumArray, Hash Table
2975Maximum Square Area by Removing Fences From a FieldMediumArray, Hash Table, Enumeration
2981Find Longest Special Substring That Occurs Thrice IMediumHash Table, String, Binary Search +2
2982Find Longest Special Substring That Occurs Thrice IIMediumHash Table, String, Binary Search +2

Hard (110)

#ProblemDifficultyTopics
30Substring with Concatenation of All WordsHardHash Table, String, Sliding Window
37Sudoku SolverHardArray, Hash Table, Backtracking +1
41First Missing PositiveHardArray, Hash Table
65Valid NumberHardString
68Text JustificationHardArray, String, Simulation
76Minimum Window SubstringHardHash Table, String, Sliding Window
126Word Ladder IIHardBreadth-First Search, Hash Table, String +1
127Word LadderHardBreadth-First Search, Hash Table, String
140Word Break IIHardTrie, Memoization, Array +4
149Max Points on a LineHardGeometry, Array, Hash Table +1
214Shortest PalindromeHardString, String Matching, Hash Function +1
336Palindrome PairsHardTrie, Array, Hash Table +1
352Data Stream as Disjoint IntervalsHardUnion Find, Design, Hash Table +3
381Insert Delete GetRandom O(1) - Duplicates allowedHardDesign, Array, Hash Table +2
391Perfect RectangleHardGeometry, Array, Hash Table +2
432All O`one Data StructureHardDesign, Hash Table, Linked List +1
460LFU CacheHardDesign, Hash Table, Linked List +1
480Sliding Window MedianHardArray, Hash Table, Sliding Window +1
632Smallest Range Covering Elements from K ListsHardGreedy, Array, Hash Table +3
691Stickers to Spell WordHardBit Manipulation, Memoization, Array +5
710Random Pick with BlacklistHardArray, Hash Table, Math +3
736Parse Lisp ExpressionHardStack, Recursion, Hash Table +1
745Prefix and Suffix SearchHardDesign, Trie, Array +2
248Strobogrammatic Number IIIPremiumHardRecursion, Array, String
305Number of Islands IIPremiumHardUnion Find, Array, Hash Table
358Rearrange String k Distance ApartPremiumHardGreedy, Hash Table, String +3
548Split Array with Equal SumPremiumHardArray, Hash Table, Prefix Sum
588Design In-Memory File SystemPremiumHardDesign, Trie, Hash Table +2
631Design Excel Sum FormulaPremiumHardGraph, Design, Topological Sort +4
711Number of Distinct Islands IIPremiumHardDepth-First Search, Breadth-First Search, Union Find +2
726Number of AtomsHardStack, Hash Table, String +1
761Special Binary StringHardRecursion, String
770Basic Calculator IVHardStack, Recursion, Hash Table +2
815Bus RoutesHardBreadth-First Search, Array, Hash Table
828Count Unique Characters of All Substrings of a Given StringHardHash Table, String, Dynamic Programming
839Similar String GroupsHardDepth-First Search, Breadth-First Search, Union Find +3
854K-Similar StringsHardBreadth-First Search, Hash Table, String
895Maximum Frequency StackHardStack, Design, Hash Table +1
924Minimize Malware SpreadHardDepth-First Search, Breadth-First Search, Union Find +3
928Minimize Malware Spread IIHardDepth-First Search, Breadth-First Search, Union Find +3
952Largest Component Size by Common FactorHardUnion Find, Array, Hash Table +2
982Triples with Bitwise AND Equal To ZeroHardBit Manipulation, Array, Hash Table
987Vertical Order Traversal of a Binary TreeHardTree, Depth-First Search, Breadth-First Search +3
992Subarrays with K Different IntegersHardArray, Hash Table, Counting +1
996Number of Squareful ArraysHardBit Manipulation, Array, Hash Table +4
1001Grid IlluminationHardArray, Hash Table
1036Escape a Large MazeHardDepth-First Search, Breadth-First Search, Array +1
1074Number of Submatrices That Sum to TargetHardArray, Hash Table, Matrix +1
1096Brace Expansion IIHardStack, Breadth-First Search, Hash Table +3
1121Divide Array Into Increasing SequencesPremiumHardArray, Counting
1153String Transforms Into Another StringPremiumHardGraph, Hash Table, String
1172Dinner Plate StacksHardStack, Design, Hash Table +1
1178Number of Valid Words for Each PuzzleHardBit Manipulation, Trie, Array +2
1224Maximum Equal FrequencyHardArray, Hash Table
1255Maximum Score Words Formed by LettersHardBit Manipulation, Array, Hash Table +5
1284Minimum Number of Flips to Convert Binary Matrix to Zero MatrixHardBit Manipulation, Breadth-First Search, Array +2
1345Jump Game IVHardBreadth-First Search, Array, Hash Table
1392Longest Happy PrefixHardString, String Matching, Hash Function +1
1542Find Longest Awesome SubstringHardBit Manipulation, Hash Table, String
1713Minimum Operations to Make a SubsequenceHardGreedy, Array, Hash Table +1
1782Count Pairs Of NodesHardGraph, Array, Hash Table +4
1788Maximize the Beauty of the GardenPremiumHardGreedy, Array, Hash Table +1
1819Number of Different Subsequences GCDsHardArray, Math, Counting +1
1857Largest Color Value in a Directed GraphHardGraph, Topological Sort, Memoization +3
1912Design Movie Rental SystemHardDesign, Array, Hash Table +2
1932Merge BSTs to Create Single BSTHardTree, Depth-First Search, Hash Table +2
1938Maximum Genetic Difference QueryHardBit Manipulation, Depth-First Search, Trie +2
1948Delete Duplicate Folders in SystemHardTrie, Array, Hash Table +2
1960Maximum Product of the Length of Two Palindromic SubstringsHardString, Hash Function, Rolling Hash
1994The Number of Good SubsetsHardBit Manipulation, Array, Hash Table +5
2009Minimum Number of Operations to Make Array ContinuousHardArray, Hash Table, Binary Search +1
2014Longest Subsequence Repeated k TimesHardGreedy, String, Backtracking +2
2019The Score of Students Solving Math ExpressionHardStack, Memoization, Array +4
2025Maximum Number of Ways to Partition an ArrayHardArray, Hash Table, Counting +2
2122Recover the Original ArrayHardArray, Hash Table, Two Pointers +2
2213Longest Substring of One Repeating CharacterHardSegment Tree, Array, String +1
2227Encrypt and Decrypt StringsHardDesign, Trie, Array +2
2251Number of Flowers in Full BloomHardArray, Hash Table, Binary Search +3
2254Design Video Sharing PlatformPremiumHardStack, Design, Hash Table +1
2262Total Appeal of A StringHardHash Table, String, Dynamic Programming
2301Match Substring After ReplacementHardArray, Hash Table, String +1
2306Naming a CompanyHardBit Manipulation, Array, Hash Table +2
2350Shortest Impossible Sequence of RollsHardGreedy, Array, Hash Table
2354Number of Excellent PairsHardBit Manipulation, Array, Hash Table +1
2402Meeting Rooms IIIHardArray, Hash Table, Sorting +2
2416Sum of Prefix Scores of StringsHardTrie, Array, String +1
2421Number of Good PathsHardTree, Union Find, Graph +3
2488Count Subarrays With Median KHardArray, Hash Table, Prefix Sum
2499Minimum Total Cost to Make Arrays UnequalHardGreedy, Array, Hash Table +1
2508Add Edges to Make Degrees of All Nodes EvenHardGraph, Hash Table
2514Count AnagramsHardHash Table, Math, String +2
2524Maximum Frequency Score of a SubarrayPremiumHardStack, Array, Hash Table +2
2547Minimum Cost to Split an ArrayHardArray, Hash Table, Dynamic Programming +1
2561Rearranging FruitsHardGreedy, Sort, Array +1
2581Count Number of Possible Root NodesHardTree, Depth-First Search, Array +2
2584Split the Array to Make Coprime ProductsHardArray, Hash Table, Math +1
2612Minimum Reverse OperationsHardBreadth-First Search, Union Find, Array +2
2713Maximum Strictly Increasing Cells in a MatrixHardMemoization, Array, Hash Table +5
2732Find a Good Subset of the MatrixHardBit Manipulation, Array, Hash Table +1
2763Sum of Imbalance Numbers of All SubarraysHardArray, Hash Table, Enumeration
2781Length of the Longest Valid SubstringHardArray, Hash Table, String +1
2813Maximum Elegance of a K-Length SubsequenceHardStack, Greedy, Array +3
2842Count K-Subsequences of a String With Maximum BeautyHardGreedy, Hash Table, Math +2
2897Apply Operations on Array to Maximize Sum of SquaresHardGreedy, Bit Manipulation, Array +1
2902Count of Sub-Multisets With Bounded SumHardArray, Hash Table, Dynamic Programming +1
2935Maximum Strong Pair XOR IIHardBit Manipulation, Trie, Array +2
2949Count Beautiful Substrings IIHardHash Table, Math, String +2
2953Count Complete SubstringsHardHash Table, String, Sliding Window
2963Count the Number of Good PartitionsHardArray, Hash Table, Math +1
2983Palindrome Rearrangement QueriesHardHash Table, String, Prefix Sum

Related patterns

Problems sit in more than one pattern more often than not, and the overlap is where the interesting follow-up questions live.

Hash Map pattern FAQ

What is the hash map pattern?

A hash map converts a search into a lookup, which is why it is the most common single answer in this entire corpus — 588 of the 3000 problems are built on one.

How many LeetCode problems use the hash map pattern?

This page lists 709 LeetCode problems that the hash map pattern applies to: 227 Easy, 372 Medium and 110 Hard. 601 of them carry a complete Python solution with complexity analysis.

What is the time complexity of the hash map pattern?

O(1) average per operation, O(n) worst case time and O(n) space. Average-case constant lookups are what turn a nested-loop search into a single pass, so the complement and frequency-counting solutions are O(n) time and O(n) space. The worst case is linear per operation when every key collides, which is irrelevant on real data and is the reason a language's string hash is randomised per process. Ordering is not free: getting a sorted result out of a map costs the sort on top.

When should I use the hash map pattern in an interview?

The brute force is a nested loop asking "is there another element such that…". You are counting occurrences, or comparing two multisets.

Which hash map problem should I start with?

LeetCode 1. Two Sum is the lowest-numbered Easy problem on this page, which makes it the usual starting point: the technique is visible without the problem's own complications getting in the way.

What patterns are related to hash map?

Prefix Sum, Sliding Window, Sorting, Trie. Problems frequently sit in more than one of these, and the overlap is where the interesting follow-up questions come from.

More ways in: all 22 patterns, the curated study lists, or the full problem list.

Meet the hash map problem you did not practise

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.