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 always sorted) this
can be done in O(n)
then sum[i]-sum[j] when j<i is the sum of range [j,i]
then for each sum[i] binary search for sum[i]-k in the array sum
which yields the overall running time of O(nlogn)

On Tue, Jun 22, 2010 at 7:48 PM, sharad kumar <sharad20073...@gmail.com>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 algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> 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 algoge...@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