Why do we use <=
in this line if (window.length && window[0] <= i - windowSize) window.shift();
instead of simple ==
?
Hi @11133
Thanks for contacting the Educative Team. In this problem, we have stored elements in the deque data structure named window [ ]
in decreasing order, and the front of the deque contains the index for the maximum value in that particular window. We should apply the following condition
if (window.length && window[0] == i - windowSize) window.shift();
to remove the first index (Index for maximum value in the particular window ) from the window deque if it is equal to the current window.
Thanks for pointing it out. We will update this in the lesson. Happy Learning