Skip to content

Instantly share code, notes, and snippets.

@RP-3
Created February 28, 2020 04:57
Show Gist options
  • Save RP-3/25e6cb2f992e7856513c223914169b71 to your computer and use it in GitHub Desktop.
Save RP-3/25e6cb2f992e7856513c223914169b71 to your computer and use it in GitHub Desktop.
var longestOnes = function(A, K) {
let result = 0;
let i=0; let j=0; let k=K;
while(j < A.length){
if(A[j] === 1){
result = Math.max(result, j-i+1);
j++;
}
else if(k>0){
result = Math.max(result, j-i+1);
k--;
j++;
}else{
if(A[i++] === 0) k++;
}
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment