Maximum Product of 3 Numbers - O(n) Time Complexity
Intuition\nTo reduce the time complexity\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n- There are two approaches Brute Force App
# Intuition\nTo reduce the time complexity\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- There are two approaches Brute Force Approach and the other one is the refined one that is using sorting.\n- I have used sorting approach to reduce the time complexity. \n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maximumProduct(vector<int>& nums) \n{\n int n = nums.size();\n    int mx[3] = {-1001,-1001,-1001};\n    int mn[2] = {1001,1001};\n    int first, sec;\n    for (int i = 0;i<n;i++)\n    {\n        if (nums[i] >= mx[0])\n        {\n            first = mx[0];\n            sec = mx[1];\n            mx[0]= nums[i];\n            mx[1]=first;\n            mx[2]=sec;\n        }\n        else if (nums[i] >= mx[1])\n        {\n            first = mx[1];\n            mx[1]= nums[i];\n            mx[2]=first;\n             \n        }\n        else if (nums[i]> mx[2])\n        {\n            mx[2] = nums[i];\n        }\n        if (nums[i]<=mn[0])\n        {\n            first = mn[0];\n            mn[0]=nums[i];\n            mn[1]=first;\n        }\n        else if(nums[i]<=mn[1])\n        {\n            mn[1]=nums[i];\n        }\n    }\n    return max(mn[0]*mn[1]*mx[0],mx[0]*mx[1]*mx[2]);\n\n\n}\nint main(){\n    return 0;\n}\n\n        \n    \n};\n\n\n  \n```
['Array', 'Dynamic Programming', 'Sorting', 'C++']