Javascript - O(n) time & O(1) space
\nvar maximumProduct = function(nums) {\n    // get top 3 max and top 2 min in one pass\n    let max1 = -Infinity, \n        max2 = -Infinity,\n        max3 = -
```\nvar maximumProduct = function(nums) {\n    // get top 3 max and top 2 min in one pass\n    let max1 = -Infinity, \n        max2 = -Infinity,\n        max3 = -Infinity,\n        min1 = Infinity,\n        min2 = Infinity;\n        \n    for(let num of nums){\n        // fetch max\n        if(num > max1){\n            max3 = max2;\n            max2 = max1;\n            max1 = num;\n        } else if(num > max2){\n            max3 = max2;\n            max2 = num;\n        } else if(num > max3){\n            max3 = num;\n        }\n        \n        // fetch min\n        if(num < min1){\n            min2 = min1;\n            min1 = num\n        } else if(num < min2){\n            min2 = num;\n        }\n    }\n    // return max of top 3, or top1 and last 2\n    return Math.max(max1 * max2 * max3, max1 * min1 * min2);\n    \n};\n```
['JavaScript']