Given an array of 1s and 0s and an integer , your task is to find the length of the longest subarray that contains no more than zeros. For instance, if the array is and , the longest subarray with no more than zeros is , and its length is .
Sliding window
Please limit the zeros
Report a typo
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 longestLengthCreate a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.