Given a binary array nums (every element is 0 or 1) and an integer k, return the length of the longest contiguous subarray that contains at most k zeros.
Examples
Example 1
Input: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
Output: 6
Explanation: The subarray from index 4 to index 9, [0,0,1,1,1,1], contains exactly 2 zeros and has length 6. No longer contiguous subarray contains 2 or fewer zeros.
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: The subarray from index 2 to index 11, [1,1,0,0,1,1,1,0,1,1], contains exactly 3 zeros and has length 10. No longer contiguous subarray contains 3 or fewer zeros.
Constraints
1≤nums.length≤105
nums[i] is either 0 or 1.
0≤k≤nums.length
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up