In the solution the condition is:
if window_end >= len(pattern) - 1:
Shouldn’t it be:
window_end - window_start + 1 > len(pattern)
That would satisfy condition 5) If the window size is greater than the length of the pattern, shrink the window to make it equal to the pattern’s size.