Where it runs
1. The problem
Where does "world" start in "hello world"? How many times does "ab" show up in "ababab"? These questions are behind every Ctrl-F, every grep, every "does this log line contain ERROR". Languages give you ready-made indexOf, strstr or in for this. Here you write the search yourself. The plain version teaches you to compare characters while sliding the pattern along the text, and many string problems reuse that move later. And once you know what the plain version costs, you can tell when you need a faster algorithm.
This step is part of the paid track
The first 33 steps are open to everyone: lesson, exercise and tests. This one opens with full access. Start with a free account and the free steps.
Create a free accountSee what is includedOn LeetCode
Problems that find a short pattern inside a text, or check whether one string sits inside another. Trying every start and comparing letter by letter costs O(n * m), which passes when the strings are short.
The lesson's findSubstring. Both strings are at most 10^4 long, so the plain search passes.
There are at most 100 words of at most 30 letters, so check every pair with the lesson's search.
s is built from one repeated piece exactly when s appears inside s + s with the first and last letters cut off.
Repeat a until it is at least as long as b, try one more copy, and search for b in each.