String Matching LeetCode Problems: All 20, With Python Solutions

Every problem in this library that LeetCode tags String Matching 20 in total, 16 of them with a complete Python solution, a worked example and the time and space complexity of the approach.

  • 20 problems
  • 8 Easy
  • 5 Medium
  • 7 Hard

String Matching problems by difficulty

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

Easy (8)

#ProblemDifficultyTopics
28Find the Index of the First Occurrence in a StringEasyTwo Pointers, String, String Matching
459Repeated Substring PatternEasyString, String Matching
572Subtree of Another TreeEasyTree, Depth-First Search, Binary Tree +2
796Rotate StringEasyString, String Matching
1408String Matching in an ArrayEasyArray, String, String Matching
1455Check If a Word Occurs As a Prefix of Any Word in a SentenceEasyTwo Pointers, String, String Matching
1668Maximum Repeating SubstringEasyString, Dynamic Programming, String Matching
2185Counting Words With a Given PrefixEasyArray, String, String Matching

Medium (5)

#ProblemDifficultyTopics
686Repeated String MatchMediumString, String Matching
1023Camelcase MatchingMediumTrie, Array, Two Pointers +2
1764Form Array by Concatenating Subarrays of Another ArrayMediumGreedy, Array, Two Pointers +1
616Add Bold Tag in StringPremiumMediumTrie, Array, Hash Table +2
758Bold Words in StringPremiumMediumTrie, Array, Hash Table +2

Hard (7)

#ProblemDifficultyTopics
214Shortest PalindromeHardString, String Matching, Hash Function +1
1392Longest Happy PrefixHardString, String Matching, Hash Function +1
2301Match Substring After ReplacementHardArray, Hash Table, String +1
2430Maximum Deletions on a StringHardString, Dynamic Programming, String Matching +2
2851String TransformationHardMath, String, Dynamic Programming +1
1397Find All Good StringsHardString, Dynamic Programming, String Matching
2223Sum of Scores of Built StringsHardString, Binary Search, String Matching +3

When the String Matching 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.