left
and right
to 0, and max_length
to 0 to keep track of the maximum length of the window.right
pointer to iterate through the array.k
is greater than 0, decrement k
.k
is 0 and a zero is encountered, increment the left
pointer until a zero is discarded from the window.max_length
with the maximum of max_length
and the current window size (right - left + 1
).max_length
as the result.