Skip to content

Instantly share code, notes, and snippets.

@hkarthik
Created May 15, 2012 03:53
Show Gist options
  • Save hkarthik/2699002 to your computer and use it in GitHub Desktop.
Save hkarthik/2699002 to your computer and use it in GitHub Desktop.
Codility Demo test in Java
class Solution {
public int equi ( int[] A ) {
int result = -1;
for(int i = 0; i < A.length; i++) {
if (lowerBound(A,i) == upperBound(A,i)) {
result = i;
break;
}
}
return result;
}
public int lowerBound(int[] A,int index) {
int sum = 0;
for(int i = 0; i < index; i++) {
sum += A[i];
}
return sum;
}
public int upperBound(int[] A,int index) {
int sum = 0;
for(int i = index+1; i < A.length; i++) {
sum += A[i];
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment