JavaScript O(n) time (1) space
javascript\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumProduct = function(nums) {\n  let max1 = -Infinity;\n  let max2 = -Infinity;\n 
```javascript\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumProduct = function(nums) {\n  let max1 = -Infinity;\n  let max2 = -Infinity;\n  let max3 = -Infinity;\n  let min2 = Infinity;\n  let min1 = Infinity;\n  for (let i = 0; i < nums.length; i++) {\n    if (nums[i] > max1) {\n      [max1, max2, max3] = [nums[i], max1, max2];\n    } else if (nums[i] > max2) {\n      [max2, max3] = [nums[i], max2];\n    } else if (nums[i] > max3) {\n      max3 = nums[i];\n    }\n    if (nums[i] < min1) {\n      [min2, min1] = [min1, nums[i]];\n    } else if (nums[i] < min2) {\n      min2 = nums[i];\n    }\n  }\n  return Math.max(max1 * max2 * max3, max1 * min1 * min2);\n};\n```
['JavaScript']