Just take 2 arrays. MinArr, MaxArr. Where MinArr[i] is Minimum product so far. and MaxArr[i] is Max Product so far.
For any position i, get MaxArr[i] = max(A[i] * MaxArr[i], A[i] * MinArr[i]); get MinArr[i] = max(A[i] * MaxArr[i], A[i] * MinArr[i]); you will have to take care, when first element is negative. For that, make MaxArr[0] = 1. and if positive, take MinArr[0] = 1; and when you strike with a zero, do similar things. On Tue, Jul 12, 2011 at 9:13 PM, shilpa gupta <[email protected]>wrote: > given an array of natural numbers (+ve, 0, -ve) find the maximum > product of continuous elements.efficient( O(nlogn) or better)solution > is needed. > thanks > > -- > 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. > > -- -Aakash Johari (IIIT Allahabad) -- 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.
