We’re preparing your current view and syncing the latest data.
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 to 1s. A flip involves changing a 0 to a 1, and the goal is to find the longest subarray consisting of 1s after such operations.
An integer array nums of 0s and 1s, and an integer k representing the maximum number of zeros you can flip.
Return an integer representing the maximum number of consecutive 1s achievable by flipping at most k zeros.
1 <= nums.length <= 10^5 nums[i] is either 0 or 1 0 <= k <= nums.length
Example 1
Input
nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
Output
6
Explanation
Flip the two zeros at positions 5 and 6 (0-based index) to 1, resulting in the longest subarray of six 1s.
Example 2
Input
nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3
Output
10
Explanation
Flip three zeros around indices to get the longest subarray of 1s of length 10.