Problem statement
Given an array of zeroes and ones and a number k, find the longest run of ones that can be produced by flipping at most k zeroes.
A flipped zero becomes a one, so the window may hold at most k zeroes and any number of ones.
Examples
Input[1, 1, 0, 0, 1, 1, 1, 0, 1], k = 2
Output6
Flipping the two zeroes at indices 2 and 3 gives a run of six.
Input[0, 0, 0], k = 2
Output2
Two zeroes can be flipped, so the run is two long.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing