Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Find a point in an array where sum of left side array members(wrt to that point) and right side(wrt to that point) are equal..in other words equilibrium point.

Go down

Find a point in an array where sum of left side array members(wrt to that point) and right side(wrt to that point) are equal..in other words equilibrium point. Empty Find a point in an array where sum of left side array members(wrt to that point) and right side(wrt to that point) are equal..in other words equilibrium point.

Post  Admin Thu Aug 25, 2011 4:26 pm

public static int FindPoint(int[] arr){
int len=arr.length()-1;
int i=0;int j=len;
int left=0;
int right=0;
while(i<j){
if(left>right+arr[j]){
right+=arr[j--];
}
else if (right>left+arr[i]){
left+=arr[i++];
}
else{
return i;

}
}
return 0;
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum