C++ DP solution
O(n) time, O(1) space\n\nclass Solution {\npublic:\n    int maximumProduct(vector<int>& nums) {\n        int f[2][4], i, j;\n        f[0][0] = f[1][0] = 1;\n   
O(n) time, O(1) space\n```\nclass Solution {\npublic:\n    int maximumProduct(vector<int>& nums) {\n        int f[2][4], i, j;\n        f[0][0] = f[1][0] = 1;\n        for (j = 3; j > 0; --j) {\n            f[0][j] = INT_MIN;\n            f[1][j] = INT_MAX;\n        }        \n        \n        for (i = 0; i < nums.size(); ++i) {\n            for (j = 3; j > 0; --j) {\n                if (f[0][j - 1] == INT_MIN) {\n                    continue;\n                }\n                f[0][j] = max(f[0][j], max(f[0][j - 1] * nums[i], f[1][j - 1] * nums[i]));\n                f[1][j] = min(f[1][j], min(f[0][j - 1] * nums[i], f[1][j - 1] * nums[i]));\n            }\n        }                              \n        return f[0][3];\n    }\n};\n```
[]