@Sharad: I think a better way is to store the partial sums a[0],
a[0]+a[1], a[0]+a[1]+a[2], etc. in a hash table, along with k, the
index of the last summand. When you get a collision, then the subarray
from k+1 to the current index sums to zero.

Dave

On Nov 6, 9:13 am, sharad kumar <[email protected]> wrote:
> keep storing the elements in hash..
> now keep adding the elements of array is the sum is -ve calculate -(-sum)
> ans search in hash.
> lllrly do it for +ve...
> O(n) in space and O(n) time i guess
>
>
>
>
>
> On Sat, Nov 6, 2010 at 7:21 PM, MAC <[email protected]> wrote:
> > an array contain +ve and -ve element, find subarray whose sum is 0
>
> > --
> > thanks
> > --mac
>
> > --
> > 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%2bunsubscr...@googlegroups­.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> yezhu malai vaasa venkataramana Govinda Govinda- Hide quoted text -
>
> - Show quoted text -

-- 
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.

Reply via email to