Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Hey, I don't understand how "if window_end >= len(pattern) - 1" check works for ...

Viktor

Oct 25, 2022

Hey, I don't understand how "if window_end >= len(pattern) - 1" check works for "If the window size is greater than the length of the pattern, shrink the window to make it equal to the pattern’s size". Because here we never subtract window_start from window_end. So actually, we shrink on every iteration starting from window_end is equal to pattern size. Hmm...

1

0

Comments
Comments
SHLOK KOTHARI
SHLOK KOTHARI2 years ago

Here is how I thought about it.

  1. The first time condition window_end >= len(pattern) - 1 becomes True is the first window in the iteration we need to check.

  2. For every index after this window_end we will need to decrease the window size, since it will be greater ...

On this page