✅Beats 100 % Easy Clean Code✅✅✅
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Tim
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n![Screenshot 2023-12-12 075050.png](https://assets.leetcode.com/users/images/17d06731-ff9b-4884-b903-aa5812c95309_1702347950.5346918.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: o(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n**C++**\n```\nclass Solution {\npublic:\n    int maxProduct(vector<int>& nums) {\n        int n = nums.size();\n        sort(nums.begin(), nums.end());\n        return (nums[n-2] - 1) * (nums[n-1] - 1);\n    }\n};\n```\n**Java**\n```\nclass Solution {\n    public int maxProduct(int[] nums) {\n        int n = nums.length;\n        Arrays.sort(nums);\n        return (nums[n - 2] - 1) * (nums[n - 1] - 1);\n    }\n}\n```\n**JavaScript**\n```\nvar maxProduct = function(nums) {\n    const n = nums.length;\n    nums.sort((a, b) => a - b);\n    return (nums[n - 2] - 1) * (nums[n - 1] - 1);\n};\n```\n![download.jpeg](https://assets.leetcode.com/users/images/be33faa9-b661-439c-bc61-e607b03d25cb_1702347967.4118521.jpeg)\n
['Array', 'Sorting', 'Heap (Priority Queue)', 'C++', 'Java', 'JavaScript']