Rust/Python 2 lines sort. Also can do linear
Intuition\nOf course you can just check each pair and it will pass, but you do not need to. If the values are all positive, the maximum will be attained with ma
# Intuition\nOf course you can just check each pair and it will pass, but you do not need to. If the values are all positive, the maximum will be attained with maximum values of two elements in the product.\n\nSo all you need is to get two maximum values in this list. You can do this in linear time (find one maximum and its position and then find next maximum which is not in that position). But this is a lot of work (more than 2 lines).\n\nInstead you can just sort and then check last two elements.\n\n# Complexity\n- Time complexity: $O(n \\log n)$\n- Space complexity: $O(1)$\n\n# Code\n```Python []\nclass Solution:\n  def maxProduct(self, nums: List[int]) -> int:\n    nums.sort()\n    return (nums[-1] - 1) * (nums[-2] - 1)\n```\n```Rust []\nimpl Solution {\n  pub fn max_product(mut nums: Vec<i32>) -> i32 {\n    nums.sort_unstable();\n    return (nums[nums.len() - 1] - 1) * (nums[nums.len() - 2] - 1);\n  }\n}\n```
['Python', 'Rust']