Maximize Number of 1's
intermediateFinds the maximum consecutive 1s achievable by flipping at most k zeros using a variable sliding window; O(n).
zeros 0/2
len 0
max 0
New Max!
1
[0]
0
[1]
1
[2]
1
[3]
0
[4]
1
[5]
0
[6]
1
[7]
1
[8]
1 in window
0 in window (will flip)
Result window
Outside window
Init: left=0, right=-1, zeros=0. Expand right and allow at most 2 zeros in the window.
1 / 13