left
and right
, to the start of the array.max_consecutive
to keep track of the maximum number of consecutive 1s found.zero_count
to keep track of the number of zeros in the current window.zero_count
.zero_count
exceeds 1, contract the window from the left until zero_count
is 1 or less.max_consecutive
with the maximum length of the window seen so far.max_consecutive
as the result.