Problems > Best Product of Three > Editorial

Best Product of Three — Solution & Editorial

Back to the Problem

After sorting, the answer is either the product of the three largest, or of the two smallest (possibly very negative) with the largest. Take the max of the two candidates.

Complexity: O(N log N)

Watch out: Two large negatives times a positive can beat three positives — one candidate is not enough.