Simple and Easy Code to understand ||Beginner Friendly||C++||java||python
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(n log n), where n is the number of elements in the input array. This is because sorting the array takes O(n log n) time.\n\n- Space complexity:\no(1)\n```c++ []\nclass Solution {\npublic:\n    int maxProductDifference(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        int n1=(nums[nums.size()-1]) * (nums[nums.size()-2]);\n        int n2=nums[0]*nums[1];\n        return n1-n2;\n    }\n};\n```\n```python []\nclass Solution:\n    def maxProductDifference(self, nums):\n        nums.sort()\n        n1 = nums[-1] * nums[-2]\n        n2 = nums[0] * nums[1]\n        return n1 - n2\n\n```\n```java []\nclass Solution {\n    public int maxProductDifference(int[] nums) {\n        Arrays.sort(nums);\n        int n1 = nums[nums.length - 1] * nums[nums.length - 2];\n        int n2 = nums[0] * nums[1];\n        return n1 - n2;\n    }\n}\n```\n![WhatsApp Image 2023-10-20 at 08.23.29.jpeg](https://assets.leetcode.com/users/images/5f734fcf-8f90-4dee-a0d5-d27328597f6b_1702874172.29762.jpeg)\n
['Sorting', 'C++', 'Java', 'Python3']