points
to 0 to store the total points.windowSum
to 0 to store the sum of calories in the current window.calories
array with an index i
.
calories[i]
to windowSum
.i
is greater than or equal to k - 1
, we have a complete window.
i
is greater than k - 1
, subtract calories[i - k]
from windowSum
to remove the element that is no longer in the window.windowSum
is less than lower
, decrement points
.windowSum
is greater than upper
, increment points
.points
as the final result.