educative.io

Educative

Why do we add 1 here

  min_length = min(min_length, window_end - window_start + 1)

why not just 'min_length = min(min_length, window_end - window_start)
'? why need to add 1?

Hey @rjthegreatxx!
Can you please provide the lesson link?

Thank you!

Hey @rjthegreatxx!
It is not inclusive when we calculate the min_length without adding 1 in it.
For example if

    window_end= 4
    window_start= 3

Then the window_end - window_start will return 1. Hence, it gives 1 as min_length while we can see that it’s 2, not 1. So to make it inclusive, we add 1 to it.