Java | Beats 100% | O(n)
Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\n    public int maxProduct(int[] nums) {\n        int max1 = 0;\n 
# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\n    public int maxProduct(int[] nums) {\n        int max1 = 0;\n        int max2 = 0;\n        int result = 0;\n        for(int i=0; i<nums.length;i++){\n            if(nums[i]>max1){\n                max2 = max1;\n                max1 = nums[i];\n            }\n            else if(nums[i]>max2){\n                max2 = nums[i];\n            }\n            result = (max1-1)*(max2-1);\n        }\n        return result;\n    }\n}\n```
['Java']