0

How to find the max product formed by multiplying three numbers of an un sorted array?

We can not sort the array. Input- {2,5,-2,6,-3,8,0,-7,-9,4}

22nd Jun 2019, 11:14 AM
Saumya Upadhyay
Saumya Upadhyay - avatar
2 ответов
0
Parse through to get the 3 biggest numbers and multiply. The harder question is if you want to get the max from 3 consecutive numbers.
22nd Jun 2019, 2:15 PM
Jackson O’Donnell
0
Two possibilities: * max product of only positive numbers * max product of two negative and one positive number You can search for the two highest numbers and for the two minimal numbers 8 * 6 = 48 (-7) * (-9) = 63 You don't need to search the third positive value because you know it can not be larger than 8. 8 * 6 * (n < 8) can not be larger than (-7) * (-9) * 8 Here is a code but I didn't test all cases (and I am sure it can be optimized): https://code.sololearn.com/cG7OiVJuTWVK/?ref=app
22nd Jun 2019, 2:19 PM
Denise Roßberg
Denise Roßberg - avatar