ones
).left
and right
, to maintain the sliding window, and a variable max_one
to store the maximum number of 1's found in any window.right
and, if the window size exceeds ones
, increment left
as well.cnt_one
) by adding the new element at right
and subtracting the element at left
if the window size exceeds ones
.max_one
with the maximum of its current value and cnt_one
.ones - max_one
.