0% completed
can someone explain the necessity of the check:if min_length == math.infin the P...
Jess
Feb 26, 2022
can someone explain the necessity of the check:
if min_length == math.inf
in the Python3 solution? How would min_length ever be an infinite number in this scenario?
0
0
Comments
Design Gurus4 years ago
It is needed for the following line:
min_length = min(min_length, window_end - window_start + 1)
When we initialize min_length to the maximum possible value, we are guaranteed to get the 'smaller' value from the 'min' function.
Alexsandro Olinda4 years ago
Hi systemdesign I think the question is about this statement if min_length == math.inf: return 0
Design Gurus4 years ago
Ah ok. It is because we initialize it that way: min_length = math.inf
And if the while loop never gets executed, which will happen when window_sum is always less than "s", that's when min_length will be "math.inf". In this case, the correct answer will be "0".
Alexsandro Olinda4 years ago
yess 👍
Jordan Rowland4 years ago
I set min_length = len(array) when I coded this because the min would never be greater than the length of the array.