Skip to content

Instantly share code, notes, and snippets.

@adicuco
Created June 16, 2018 15:09
Show Gist options
  • Save adicuco/83e104975c62170f2c34253c7161d081 to your computer and use it in GitHub Desktop.
Save adicuco/83e104975c62170f2c34253c7161d081 to your computer and use it in GitHub Desktop.
100 % solution for Passing Cars Task on Codility
function solution(A) {
var zero = 0;
var count = 0;
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) zero++;
else {
count += 1 * zero;
if (count > 1000000000) return -1;
}
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment