Javascript Solution With Explanation
Explanation :-\nExample : - [-4 ,-3, -2, -1, 60]\nWe first sort the array in increasing order\nIf the above example had all positive integers, we would have sim
Explanation :-\nExample : - [-4 ,-3, -2, -1, 60]\nWe first sort the array in increasing order\nIf the above example had all positive integers, we would have simply done the product of 3 largest numbers.\nBut since it also has negative numbers , and we know negative multiplied by negative is positive , we can consider the first 2 negative numbers and the last number(which is the greatest)\n\nIf we choose 3 largest number --> 60 x -1 x-2 = 120\nIf we choose first 2 numbers and the last(largest) --> -4 x -3 x 60 = 720\nMath.max(120,720) ---->720\n\n```\nvar maximumProduct = function(nums) {\n    let max = nums.sort((a, b) => a - b)\n    let product1 = max[0] * max[1] * max[nums.length - 1]\n    let product2 = max[nums.length - 1] * max[nums.length - 2] * max[nums.length - 3]\n    return Math.max(product1, product2)\n};\n\n
['JavaScript']