Please limit the zeros

Report a typo

Given an array of 1s and 0s and an integer KK, your task is to find the length of the longest subarray that contains no more than KK zeros. For instance, if the array is [1,1,0,0,1,1,0,1,1,1][1,1,0,0,1,1,0,1,1,1] and K=2K = 2, the longest subarray with no more than 22 zeros is [0,1,1,0,1,1,1][0,1,1,0,1,1,1], and its length is 77.

Fill in the gaps with the relevant elements
function longestSubarray(array, K):
    start = 1
    zeros = 0
    longestLength = 0

    for end from 1 to length(array):
        if array[end] == 0:
            
        while zeros > K:
            if array[start] == 0:
                
            
        longestLength = 

    return longestLength
zeros++start++zeros--max(longestLength, end - start + 1)

Create a free account to access the full topic