Max Consecutive Ones III is LeetCode problem 1004, commonly asked in Amazon interviews with tags like Array, Sliding Window, Binary Search, and Prefix Sum.[1][2][9]
Given a binary array nums consisting of 0s and 1s, and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0s to 1s. A subarray is a contiguous part of the array.[2][7][9]
Input: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
Output: 6
Explanation: Flip both 0s at indices 3 and 4 to get six consecutive 1s: [1,1,1,1,1,1,1,1,1,1,0] (subarray from index 0 to 5).[9][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 the first three 0s to achieve ten consecutive 1s.[9]
Input: nums = [1,1,1,1,1,1,1,1,1,1], k = 0
Output: 10
Explanation: No flips needed; the entire array is already ten 1s.[1][9]
1 <= nums.length <= 10^5nums[i] is either 0 or 10 <= k <= nums.length[2][9]