Compute PrefixSum Array. PrefixSum[i]=a[0]+a[1]+a[2]+....+a[i-1]+a[i] Now problem reduces to finding two elements having same value.
For PrefixSum[i], search an element having value PrefixSum[i] in array PrefixSum from indices 0 to i-1. Linear search would cost O(n^2), balanced tree O(nlogn), hash O(n). -- 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.