C++ || Easy Solution || O(N) Solution
Intuition\nLet us say the pair is nums[i] and nums[j] (where nums[i]>=nums[j]) where i!=j and 0<=i,j=mx we found an element greater than mx so our mx is nums[i]
# Intuition\nLet us say the pair is nums[i] and nums[j] (where nums[i]>=nums[j]) where i!=j and 0<=i,j<n.\n(nums[i]-1)*(nums[j]-1) will be maximum if nums[i] and nums[j] are the first and second maximum elements in the array respectively.\n\n# Approach\n- **Sorting:**\nLet us sort the array last two elements will be our target elements so return (nums[n-1]-1)*(nums[n-2]-1).\n\n- **Two Variable Approach:**\nLet us consider two variables mx and smx. Now initialise mx with maximum of nums[0] & nums[1] and smx with minimum of nums[0] & nums[1] so till 2 elements these are the first and second maximum elements in the array. \n\nLet us traverse the array from index 2. If nums[i]>=mx we found an element greater than mx so our mx is nums[i] but smx is also changed smx will be our previous mx.\n\nThere is a catch here. There might be a case where nums[i]<mx but nums[i]>smx then we need to change smx to nums[i] because that would be our second maximum element.\n\n\n# Complexity\n- Time complexity:\nSorting: \nO(NLogN)\nTwo Variable Approach\nO(N)\n\n- Space complexity:\nSorting: \nO(1)\nTwo Variable Approach\nO(1)\n\n# Code\n```\n// TC: O(NLOGN)\nclass Solution {\npublic:\n    int maxProduct(vector<int>& nums) {\n        int n = nums.size();\n        sort(nums.begin(),nums.end());\n        return (nums[n-1]-1)*(nums[n-2]-1);\n    }\n};\n```\n```\n// TC: O(N)\nclass Solution {\npublic:\n    int maxProduct(vector<int>& nums) {\n        int n = nums.size();\n        int mx = max(nums[0],nums[1]);\n        int smx = min(nums[0],nums[1]);\n        for(int i = 2;i<n;i++){\n            if(mx <= nums[i]){\n                smx = mx;\n                mx = nums[i];\n            }else if(mx>nums[i] && smx<nums[i]){\n                smx = nums[i];\n            }\n        }\n        mx--;\n        smx--;\n        int ans = mx*smx;\n        return ans;\n    }\n};\n```
['C++']