Beats 100% of users with C++ , Brute Force Approach ( Constant Space )
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n\n\n\n\n\nif you like the approach please upvote it\n\n\n\n\n\n\nif you like the ap
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n\n\n\n\n\nif you like the approach please upvote it\n\n\n\n![image.png](https://assets.leetcode.com/users/images/7495fea3-7639-48a4-8ad9-79dc9237db4e_1701793058.7524364.png)\n\n\nif you like the approach please upvote it\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> O ( N )\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --> O ( 1 )\n\n# Code\n```\nclass Solution {\npublic:\n    int maxProduct(vector<int>& nums) \n    {\n        int max;\n        int second_max;\n        int ans=0;\n        if(nums[0]>nums[1])\n        {    max=nums[0];\n            second_max=nums[1];\n        }\n        else\n        {\n            second_max=nums[0];\n            max=nums[1];\n        }\n        for(int i=2;i<nums.size();i++)\n        {\n            if(nums[i]>max)\n            {\n                second_max=max;\n                max=nums[i];\n            }\n            else\n            {\n                if(nums[i]>second_max)\n                    second_max=nums[i];\n            }\n        }\n        max--;\n        second_max--;\n        ans=max*second_max;\n        return ans;\n    }\n};\n```
['Math', 'C++']