#K71787. Maximum Product of Three Numbers
Maximum Product of Three Numbers
Maximum Product of Three Numbers
You are given a list containing n integers. Your task is to compute the maximum product achievable by multiplying any three distinct integers from the list.
Note: The list will always contain at least three numbers. Negative numbers can influence the product as the multiplication of two negative numbers becomes positive. Therefore, consider both the three largest numbers and the combination of the two smallest (most negative) numbers with the largest number.
The optimal solution typically involves sorting the list and comparing the product of the three largest numbers vs. the product of the two smallest numbers and the largest number. The answer must be printed to standard output.
inputFormat
The first line of input contains an integer n (n ≥ 3) denoting the number of integers. The second line contains n space-separated integers representing the list.
outputFormat
Output a single integer: the maximum product of any three numbers from the list.## sample
6
3 2 1 5 6 7
210