Max Consecutive Ones III
Find the longest run of 1s you can make by flipping at most k zeros, with a window that grows right and shrinks left.
01The problem
nums holds only 0s and 1s. You may flip at most k zeros into ones. Return the length of the longest run of 1s you can make. In other words: the longest window containing at most k zeros.
| Input | Output |
|---|---|
[1,1,1,0,0,0,1,1,1,1,0], k = 2 | 6 |
[0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3 | 10 |
Constraints: 1 to 100,000 values, 0 ≤ k ≤ n.
Loading the rest of the lesson…