5 hands-on exercises and 5 find-the-bug challenges for the String Matching: KMP and Rabin-Karp lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Show the index where the pattern first appears.
Write a nested-loop search and show the index found.
Build the KMP failure table for the pattern and join it.
Count how many times the pattern appears, overlapping allowed.
Show the word absent when the pattern is not present.
indexOf returns 0 for a match at the start, which is falsy.
Looping to the full length reads past the end and never matches.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspaceThe table's first entry is always 0, so the loop must start at one.
Skipping a whole pattern length misses overlapping matches.
Two different strings can share a hash, so a match must be confirmed character by character.