O(n) solution is pretty simple, without using a greedy strategy.

prod[i] denotes product of ith, i+1th and i+2th elements.
prod[i+1] is simply (prod[i]/arr[i])*(arr[(i+1)+2]).

Answer would be the maximum product value. Do note that if prod[i] is zero,
do not use the above formula, instead simply multiply the ith, i+1th and
i+2th elements.

On Sun, Aug 7, 2011 at 8:28 PM, Debabrata Das <
[email protected]> wrote:

> why do you need three smallest number, two would suffice ?
>
>
> On Sun, Aug 7, 2011 at 7:47 PM, Amol Sharma <[email protected]>wrote:
>
>> yes...it should work !!
>> --
>>
>>
>> Amol Sharma
>> Third Year Student
>> Computer Science and Engineering
>> MNNIT Allahabad
>>
>>
>>
>>
>> On Sun, Aug 7, 2011 at 7:13 PM, Prakash D <[email protected]> wrote:
>>
>>> 1
>>>
>>
>>  --
>> 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.
>>
>
>  --
> 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.
>



-- 
Gaurav Menghani

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