DDSA Solutions

String Matching

5 problems · 4 with full explanations

1 Easy0 Medium1 Hard
String matching finds occurrences of a pattern in text. KMP runs in O(n+m) using a failure function to skip redundant comparisons. Rabin-Karp uses rolling hashes for average O(n+m). Z-algorithm and suffix arrays support more general substring queries.

How to practice

To practice String Matching problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the string matching pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.

Open the full study guide →

Start here (Easy + explained)

All String Matching problems