C++ Solution in Linear TC (First and second largest/smallest elements)
Code\r\n\r\nclass Solution {\r\n    pair<int,int> maxi(vector<int>& nums){\r\n        int max1=INT_MIN,max2=INT_MIN;\r\n        for(auto i:nums){\r\n           
# Code\r\n```\r\nclass Solution {\r\n    pair<int,int> maxi(vector<int>& nums){\r\n        int max1=INT_MIN,max2=INT_MIN;\r\n        for(auto i:nums){\r\n            if(i>=max1){\r\n                max2=max1;\r\n                max1=i;\r\n            }\r\n            else if(i>max2)\r\n                max2=i;\r\n        }\r\n        return {max1,max2};\r\n    }\r\n    pair<int,int> mini(vector<int>& nums){\r\n        int min1=INT_MAX,min2=INT_MAX;\r\n        for(auto i:nums){\r\n            if(i<=min1){\r\n                min2=min1;\r\n                min1=i;\r\n            }\r\n            else if(i<min2)\r\n                min2=i;\r\n        }\r\n        return {min1,min2};\r\n    }\r\npublic:\r\n    int maxProductDifference(vector<int>& nums) {\r\n        pair<int,int>p1=maxi(nums);\r\n        pair<int,int>p2=mini(nums);\r\n        int prod=p1.first*p1.second;\r\n        prod-=p2.first*p2.second;\r\n        return prod;\r\n    }\r\n};\r\n```
['C++']