rajesh
BAN USER
Comments (6)
Reputation -25
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
None of the above would work for -ve values:
below would work:
public static int equilibrium(int[] data){
int equilibriumSum = 0;
for (int i = 0; i < (data.length-1) ; i++){
equilibriumSum += data[i];
}
int checkSum = 0;
for(int i = data.length-1; i > 0; i--){
checkSum += data[i];
equilibriumSum -= data[i-1];
if(equilibriumSum == checkSum)
return i-1;
}
return -1;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Math.pow(n, 0.5)
- rajesh April 23, 2012