Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Last active August 29, 2015 14:19
Show Gist options
  • Save stephen-maina/383c6fae88c78ff6b2f7 to your computer and use it in GitHub Desktop.
Save stephen-maina/383c6fae88c78ff6b2f7 to your computer and use it in GitHub Desktop.
Passing cars codility fast
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int count=0;
int pair=0;
for(int index=0;index<A.length;index++){
if(A[index]==0){
count++;
}else{
pair+=count;
if(pair>1000000000){
return -1;
}
}
}
return pair;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment