✅ C++ Solution 🔥 Fastest Solution , Beats 100% , O(N) time Complexity , O(1) Space Complexity🔥
\r\n\r\n# Intuition\r\n Describe your first thoughts on how to solve this problem. \r\nMaximum product = (largest elements * secondlargest element) - (Smallest 
![100% beats 2.png](https://assets.leetcode.com/users/images/77df2bfe-a8d6-426f-bd06-832c33518ecb_1702882475.7182817.png)\r\n\r\n# Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n$$Maximum product = (largest elements * secondlargest element) - (Smallest element * secondsmallest element)$$\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\nJust take four variables in which one store the largest element , another one store second largest element , another one store smallest element and lastone store the second smallest element . In one traversal we get all values . just return the maximum product . \r\n\r\n# Complexity\r\n- Time complexity: O(N)\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity: O(1)\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        int lar1=INT_MIN;\r\n        int lar2=INT_MIN;\r\n\r\n        int small1=INT_MAX;\r\n        int small2=INT_MAX;\r\n\r\n        for(auto it:nums){\r\n            if(it>lar1){\r\n                lar2=lar1;\r\n                lar1=it;\r\n            }\r\n            else if(it>lar2){\r\n                lar2=it;\r\n            }\r\n            if(it<small1){\r\n                small2=small1;\r\n                small1=it;\r\n            }\r\n            else if(it<small2){\r\n                 small2=it;\r\n            }\r\n        }\r\n        return (lar1 * lar2)-(small1*small2);\r\n    }\r\n};\r\n```\r\n![UPvote2.jpg](https://assets.leetcode.com/users/images/ac2a1256-a0d8-49fd-978e-e49233c991cb_1702882498.7836573.jpeg)\r\n
['C++']