Created
March 18, 2015 00:35
-
-
Save kexoth/af2857ccc292180c910b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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