c++ | Two approaches | Fast solution | Asked in interview
\n\n\n////Sorting method\n\nclass Solution {\npublic:\n    int maximumProduct(vector<int>& a) {\n        sort(a.begin(),a.end());\n        int n=a.size();\n    
\n\n```\n////Sorting method\n\nclass Solution {\npublic:\n    int maximumProduct(vector<int>& a) {\n        sort(a.begin(),a.end());\n        int n=a.size();\n        return max(a[n-1]*a[n-2]*a[n-3],max(a[0]*a[1]*a[2],a[0]*a[1]*a[n-1]));\n        \n    }\n};\n\n////linear solution \n\nclass Solution {\npublic:\n    int maximumProduct(vector<int>& nums) {\n        int mn1=10001,mn2=10001,mx1=-10001,mx2=-10001,mx3=-10001;\n        for(auto& i:nums){\n            if(i>mx1){\n                mx3=mx2;\n                mx2=mx1;\n                mx1=i;\n            }\n            else if(i>mx2){                \n                mx3=mx2;\n                mx2=i;\n            }\n            else if(i>mx3)mx3=i;\n            if(i<mn1){\n                mn2=mn1;\n                mn1=i;\n            }else if(i<mn2)mn2=i;\n        }\n        return max(mn1*mn2*mx1,mx1*mx2*mx3);        \n    }\n};\n```
['C', 'Sorting']