Description
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.
Examples
Input:
nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2Output:
6Explanation:
Flip 2 zeros for longest 1s sequence.
Input:
nums = [1], k = 2Output:
1Explanation:
Edge case with a single-element array.
Input:
nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0], k = 3Output:
9Explanation:
It is possible to flip at most 3 zeros. The optimal subarray is [1,1,0,0,1,1,1,0,1,1] (indices 2-11), where flipping the 3 zeros at positions 4, 5, and 9 to get 9 consecutive ones.
Constraints
- •
1 ≤ nums.length ≤ 10⁵