Re: [algogeeks] sum k in sub array

2010-06-24 Thread divya jain
@amir ur algo works only for positive elements array.. correct me if m wrong On 23 June 2010 00:28, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: for each element find sum[i] which is the summation of all elements with index less than or equal to i ( note that this array is

[algogeeks] sum k in sub array

2010-06-22 Thread sharad kumar
How will you find the subarray whose sum is k in an array of negative and positive numbers -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send

Re: [algogeeks] sum k in sub array

2010-06-22 Thread Amit Jaspal
Let A[] be a array. Step 1: Find Cumulative Sum array say C[] if A[]={2,-1,3,5,6,-7,8} C[]={0,2,1,4,9,15,18,16} Now traverse through this C[] and keep storing C[i] in a BST. Whenever C[j]-C[i] = K (We have found our needed subarray) So for every element of C[] chk if C[i]-K is found in BST . If