sry for last post:
the code bye sravan reddy would not work for  negative nos.
but slight modification in if conditions make it work for negative nos too.
by the way nice algo suggested


#include<stdio.h>

int main(int argc, char **argv){
        int a[] = {-2,-3,-4,-19,10};
      //int a[]={2,8,-6};
      //int a[]={2,2,13,4,7,3,8,12,9,1,5};
        int len = sizeof(a)/sizeof(a[0]);

        for(int i=0;i<len;i++){
                int left=0,right=0;
                int p1 = i;
                int p2 = i+1;
                left = left + a[p1];
                right = right + a[p2];
                while(p1>=0 && p2< len){
                        if( left == right){
                 printf("Possible for \tLeft : %d, Right: %d, Center: %d
\n",p1,p2,i);
                                break;
                                //return 0;
                        }
                        else if(((left > right && p2 < len-1 &&
a[p2+1]>0))|| ((a[p2+1]<0))){
                                p2++;
                                right = right+ a[p2];
                        }
                        else if(((left < right && p1 > 0)&& a[p1-1]>0)||
((a[p1-1]<0))){
                                p1--;
                                left = left + a[p1];
                        }
                        else{
                 printf("Not Possible for \t Left : %d, Right: %d, Center:
%d \n",p1,p2,i);

                                break;
                                //return 0;
                        }
                }

        }








On Tue, Jan 10, 2012 at 10:42 AM, priyanka jaggi
<priyankajag...@gmail.com>wrote:

> @ankur : in this question, the elements of the array are continuous
>
> i think the solution of shravan reddy is correct and works for negative
> nos too.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to