educative.io

Educative

Help with conditional for shrinking window

I don’t fully understand the condition to shrink the window. windowEnd will reach a point in which it is greater than the pattern.length, right?


Type your question above this line.

Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/4679331609575424

Hi @Alejandro_Alamina. The reason to reduce the window size is to find only the permutation with the appropriate length. For example: if window size for pattern.length ‘abc’ goes above 3, it needs to be reduced such that its window size is fixed to 3.
The second part of your query correctly points out that windowEnd size will eventually get greater than the pattern.length. This is because the window size is defined by both windowStart and windowEnd combined, and not by windowEnd alone. Once the condition (windowEnd >= pattern.length) is fulfilled then the window size is maintained by both windowStart and windowEnd.

1 Like