medium

Max Consecutive Ones III

You have a binary array and may flip at most k zeros to ones. Return the length of the longest contiguous run of ones achievable after at most k flips.

Constraints
  • 1 ≤ n ≤ 10^5
  • nums[i] ∈ {0, 1}
  • 0 ≤ k ≤ n
Examples
in: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
out: 6
Flip the two zeros before the last run: 1,1,1,1,1,1.

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.