Given an array of ints, arrayofints
, find the highest product, Highestproduct
, you can get from three of the integers. The input array of ints will always have at least three integers.
So I've popped three numbers from arrayofints
and stuck them in highestproduct
:
Highestproduct = arrayofints[:2]
for item in arrayofints[3:]:
If min(Highestproduct) < item:
Highestproduct[highestproduct.index(min(Highestproduct))] = item
If min
of highestproduct
less than item: Replace the lowest number with the current number.
This would end up with highest product, but apparently there is a better solution. What's wrong with my approach? Would my solution be O(n)?