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)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 28 | Find the Index of the First Occurrence in a String | Easy | Two Pointers, String, String Matching |
| 459 | Repeated Substring Pattern | Easy | String, String Matching |
| 572 | Subtree of Another Tree | Easy | Tree, Depth-First Search, Binary Tree +2 |
| 796 | Rotate String | Easy | String, String Matching |
| 1408 | String Matching in an Array | Easy | Array, String, String Matching |
| 1455 | Check If a Word Occurs As a Prefix of Any Word in a Sentence | Easy | Two Pointers, String, String Matching |
| 1668 | Maximum Repeating Substring | Easy | String, Dynamic Programming, String Matching |
| 2185 | Counting Words With a Given Prefix | Easy | Array, String, String Matching |
Medium (5)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 686 | Repeated String Match | Medium | String, String Matching |
| 1023 | Camelcase Matching | Medium | Trie, Array, Two Pointers +2 |
| 1764 | Form Array by Concatenating Subarrays of Another Array | Medium | Greedy, Array, Two Pointers +1 |
| 616 | Add Bold Tag in StringPremium | Medium | Trie, Array, Hash Table +2 |
| 758 | Bold Words in StringPremium | Medium | Trie, Array, Hash Table +2 |
Hard (7)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 214 | Shortest Palindrome | Hard | String, String Matching, Hash Function +1 |
| 1392 | Longest Happy Prefix | Hard | String, String Matching, Hash Function +1 |
| 2301 | Match Substring After Replacement | Hard | Array, Hash Table, String +1 |
| 2430 | Maximum Deletions on a String | Hard | String, Dynamic Programming, String Matching +2 |
| 2851 | String Transformation | Hard | Math, String, Dynamic Programming +1 |
| 1397 | Find All Good Strings | Hard | String, Dynamic Programming, String Matching |
| 2223 | Sum of Scores of Built Strings | Hard | String, Binary Search, String Matching +3 |
Keep exploring
All LeetCode topicsEvery tag with a page of its own, with the number of problems behind each.LeetCode patternsThe techniques themselves, with a Python template and complexity for each.Curated study listsBlind 75, NeetCode 150 and three more, grouped by pattern.Easy problemsStart here when the data structure is new rather than the problem.
Other topics
- Array1,569
- String672
- Hash Table588
- 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
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.