Max Consecutive Ones III
MediumSliding Window
Decode it first. Clues, constraints, pattern and plan before any code.You get a binary array nums and an integer k. You may flip at most k zeros to ones. Return the length of the longest run of consecutive 1s you can end up with.
nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0], k = 2 → 6
nums = [0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1], k = 3 → 10Constraints
1 <= nums.length <= 10^5nums[i]is either0or1.0 <= k <= nums.length