100 % BEATS in TIME AND SPACE
Intuition\r\n Describe your first thoughts on how to solve this problem. \r\n\r\n# Approach\r\n Describe your approach to solving the problem. \r\n\r\n# Complex
# Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\r\n\r\n# Code\r\n```\r\nclass Solution {\r\npublic:\r\n    int maxProductDifference(vector<int>& nums) {\r\n        // sort(nums.begin(),nums.end());\r\n        int n=nums.size();\r\n        // return (nums[n-1]*nums[n-2]-nums[0]*nums[1]);\r\n        int fm=INT_MAX,sm=INT_MAX,fmax=INT_MIN,smax=INT_MIN;\r\n        for(int i=0;i<n;i++){\r\n            if(nums[i]<=fm){\r\n                sm=fm;\r\n                fm=nums[i];\r\n            }\r\n            else if(nums[i]<sm){\r\n                sm=nums[i];\r\n            }\r\n            if(nums[i]>=fmax){\r\n                smax=fmax;\r\n                fmax=nums[i];\r\n            }\r\n            else if(nums[i]>smax){\r\n                smax=nums[i];\r\n            }\r\n        }\r\n        return (fmax*smax-sm*fm);\r\n    }\r\n\r\n};\r\n```
['C++']