🔥 ⓶ line 🧠java solution🚀  | |  🙌 Easy 💯  | |  ✅Green beats
\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nFirst we are Sorting the Array and After sorting, nums[nums.length-1] and nums[num
\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nFirst we are Sorting the Array and After sorting, nums[nums.length-1] and nums[nums.length-2] represent the two largest elements, and nums[0] and nums[1] represent the two smallest elements. The method then returns the difference between the product of the two largest elements and the product of the two smallest elements.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: **O(log(n))**\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```\nclass Solution {\n    public int maxProductDifference(int[] nums) {\n        Arrays.sort(nums);\n        return (nums[nums.length-1]*nums[nums.length-2])-(nums[0]*nums[1]);\n    }\n}\n```\n![WhatsApp Image 2023-12-03 at 12.33.52.jpeg](https://assets.leetcode.com/users/images/71fe3cda-8e3c-4a9c-9f7f-6f5b96ecfccf_1702895914.9514232.jpeg)\n
['Java']