Loading...
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.
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.
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.
nums.length ≤105nums[i] is either 0 or 1.k ≤ nums.lengthClick "Run" to test with sample cases or "Submit" to run all tests.