30:00
Given a binary array nums and an integer k, return the maximum number of consecutive 1s in the array if you can flip at most k 0s to 1s.
nums
k
1
0
1≤nums.length≤1051 \leq \text{nums.length} \leq 10^51≤nums.length≤105
nums[i]\text{nums}[i]nums[i] is either 000 or 111
0≤k≤nums.length0 \leq k \leq \text{nums.length}0≤k≤nums.length
Run code to see results.
Grow a window from the left. It may hold at most k = 2 zeros, which we pretend are flipped to 1.
flip budget: 0 of 2 used
2
3
4
5
6
7
8
9
10
window
zeros in window
best
Given a binary array and a budget of k flips from 0 to 1, return the length of the longest run of ones you can make.