3 Approach to solve using C++ STL
Before getting into the problem this is somewhat easy problem and introduction to concept called as Heap.\n\nHere we need to get the maximum product so sort the
*Before getting into the problem this is somewhat easy problem and introduction to concept called as **Heap**.*\n\nHere we need to get the maximum product so sort the array and multiply last-1 and penultimate number - 1 will give us the answer.\n\nTime Complexity: O(nlogn).\n```\nclass Solution {\npublic:\n    int maxProduct(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        int n=nums.size();\n        return (nums[n-1]-1)*(nums[n-2]-1);\n    }\n};\n```\n**Introduction to Heap:**\n* \t**Using min Heap:**\n\t\tMin heap can be easily implemented using priority_queue and this solution provide a time Complexity of O(nlog(n-2))\n```\nclass Solution {\npublic:\n    int maxProduct(vector<int>& nums) {\n        // here we can use min heap \n        // using c++ stl priority queue\n        priority_queue<int,vector<int>,greater<int>> minh;\n        for(auto curr:nums) minh.push(curr);\n        while(minh.size()!=2)   minh.pop();\n        int a = minh.top();\n        minh.pop();;\n        int b = minh.top();\n        return (a-1)*(b-1);\n    }\n};\n```\n* **Using max Heap:**\n\t\tMax heap is somewhat better approach as we need to just pop() first two elements. And Time Complexity is O(nlog(2))\n```\nclass Solution {\npublic:\n    int maxProduct(vector<int>& nums) {\n        // here we can use max heap \n        // using c++ stl priority queue\n        priority_queue<int> maxh;\n        for(auto curr:nums) maxh.push(curr);\n        int a = maxh.top();\n        maxh.pop();;\n        int b = maxh.top();\n        return (a-1)*(b-1);\n    }\n};\n```\n\nHere is the final Result:\n![image](https://assets.leetcode.com/users/images/de46e472-e4ab-4c47-817d-b1d606eafbc1_1625810517.0095756.png)\n
['C', 'Heap (Priority Queue)', 'C++']