Maximum Product of Three Numbers



Create a function that takes an integer array nums and returns the highest product obtainable by multiplying any three numbers from the array.

The function should consider both positive and negative numbers to find the maximum possible product.


maxProductOfThree([1,2,3]) // 6 // Why? The product of 1, 2, and 3 is 6, which is the maximum possible product. maxProductOfThree([1,2,3,4]) // 24 // Why? The product of 2, 3, and 4 is 24, which is the maximum possible product. maxProductOfThree([-1,-2,-3]) // -6 // Why? The product of -1, -2, and -3 is -6. Given all numbers are negative, this is the maximum product.