Hash Function LeetCode Problems: All 25, With Python Solutions

Every problem in this library that LeetCode tags Hash Function 25 in total, 18 of them with a complete Python solution, a worked example and the time and space complexity of the approach.

  • 25 problems
  • 3 Easy
  • 10 Medium
  • 12 Hard

Hash Function problems by difficulty

Problems with a complete Python solution are listed first, then by ascending problem number.

Easy (3)

#ProblemDifficultyTopics
572Subtree of Another TreeEasyTree, Depth-First Search, Binary Tree +2
705Design HashSetEasyDesign, Array, Hash Table +2
706Design HashMapEasyDesign, Array, Hash Table +2

Medium (10)

#ProblemDifficultyTopics
187Repeated DNA SequencesMediumBit Manipulation, Hash Table, String +3
535Encode and Decode TinyURLMediumDesign, Hash Table, String +1
718Maximum Length of Repeated SubarrayMediumArray, Binary Search, Dynamic Programming +3
1461Check If a String Contains All Binary Codes of Size KMediumBit Manipulation, Hash Table, String +2
2261K Divisible Elements SubarraysMediumTrie, Array, Hash Table +3
694Number of Distinct IslandsPremiumMediumDepth-First Search, Breadth-First Search, Union Find +2
1062Longest Repeating SubstringPremiumMediumString, Binary Search, Dynamic Programming +3
1554Strings Differ by One CharacterPremiumMediumHash Table, String, Hash Function +1
1698Number of Distinct Substrings in a StringPremiumMediumTrie, String, Suffix Array +2
2168Unique Substrings With Equal Digit FrequencyPremiumMediumHash Table, String, Counting +2

Hard (12)

#ProblemDifficultyTopics
214Shortest PalindromeHardString, String Matching, Hash Function +1
1044Longest Duplicate SubstringHardString, Binary Search, Suffix Array +3
1147Longest Chunked Palindrome DecompositionHardGreedy, Two Pointers, String +3
1316Distinct Echo SubstringsHardTrie, String, Hash Function +1
1392Longest Happy PrefixHardString, String Matching, Hash Function +1
1923Longest Common SubpathHardArray, Binary Search, Suffix Array +2
1948Delete Duplicate Folders in SystemHardTrie, Array, Hash Table +2
1960Maximum Product of the Length of Two Palindromic SubstringsHardString, Hash Function, Rolling Hash
2156Find Substring With Given Hash ValueHardString, Sliding Window, Hash Function +1
2430Maximum Deletions on a StringHardString, Dynamic Programming, String Matching +2
711Number of Distinct Islands IIPremiumHardDepth-First Search, Breadth-First Search, Union Find +2
2223Sum of Scores of Built StringsHardString, Binary Search, String Matching +3

When the Hash Function 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.