text and a pattern pattern. The pattern consists of lowercase English letters and exactly two * characters, and it starts with a letter. Each * stands for any sequence of characters, possibly empty; the letters of the pattern must match literally.
Find the shortest substring (a contiguous piece) of text that matches the whole pattern and return its length. If there is no such substring, return -1.text="xabyyabzcab", pattern="ab*ab*c" → 8
The piece abyyabzc fits: ab, the gap yy, ab, the gap z, then c. Its length is 8, and nothing shorter works.
text="rotor", pattern="o**o" → 3
Both stars may stay empty: oto of length 3 fits.
text="pattern", pattern="t*e*a" → -1
There is no a in the text after t and e.
text consists of lowercase English letterspattern consists of lowercase English letters and exactly two *pattern is a lettertext="xabyyabzcab", pattern="ab*ab*c"
8
Run checks the first 3 tests in your browser. Submit checks all 19 tests on the server, hidden ones included.