Back to problems

Substring Pattern Matches

Algorithm · Apple · Easy

Given a string s and a nonempty string pattern, find all start positions i in s such that s[i..i + pattern.length - 1] is identical to pattern. List the positions from smallest to largest. Matches may overlap, so finding one occurrence at i does not rule out another at i + 1. The interview version of this task requested a generator that emits a signal whenever a portion of s matches the pattern. Producing the complete list of matching starting positions is the equivalent…

Checking your access…