Skip to content

Instantly share code, notes, and snippets.

@kexoth
Created March 18, 2015 00:35
Show Gist options
  • Save kexoth/af2857ccc292180c910b to your computer and use it in GitHub Desktop.
Save kexoth/af2857ccc292180c910b to your computer and use it in GitHub Desktop.
function solution(A) {
var cars0 = 0,
cars1 = 0,
combinations = 0;
for (var i = A.length - 1; i >= 0; i--) {
if (A[i] === 0) {
cars0++;
combinations += cars1;
}
else {
cars1++;
}
console.log("Combinations for A[" + i + "]:" + combinations);
if (combinations > 1000000000) return -1;
}
return combinations;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment