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 not store it in a BST. O(nlogn) Note: We can do bttr by doing Hashing but would again have Space Constraints.... On Tue, Jun 22, 2010 at 8:48 PM, sharad kumar <[email protected]>wrote: > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
