A calibration rig reports n sensor gain readings (each an integer, possibly zero or negative). For each position i, consider the product of all readings except the one at i. Output the maximum such leave-one-out product over all positions.
Because there are at least two readings, every leave-one-out product is a product of at least one reading and is well defined.
Line 1: an integer n.
Line 2: n space-separated integers, the gain readings.
A single integer: the maximum product obtainable by omitting exactly one reading.
Example 1
Input
3 3 -2 4
Expected
12
Explanation
Omit 3 -> (-2)*4 = -8; omit -2 -> 3*4 = 12; omit 4 -> 3*(-2) = -6. The maximum is 12.
Example 2
Input
4 0 5 -1 2
Expected
0
Explanation
Omitting the 0 gives 5*(-1)*2 = -10; omitting any other reading still includes the 0, giving 0. The maximum is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →