C++ || 100% faster O(n) without sorting || 2 solutions ✔
Logic :\nMax product of three no. come from\n\t\t1. product of 3 maximum positive no.\n\t\t2. product of 2 minimum negative no. and 1 maximum positive no.\n\nSo
### **Logic :**\n**Max product of three no. come from**\n\t\t**1. product of `3 maximum positive no.`**\n\t\t**2. product of `2 minimum negative no.` and `1 maximum positive no.`**\n\n*So bellow **two** solution is based on this logic :)*\n\n### **1. Sort based solution**\n**TC = O(nlogn)\nSC = O(1)**\n```\nclass Solution {\npublic:\n\tint maximumProduct(vector<int>&a) {\n\t\tsort(a.begin(), a.end());\n\t\tint n = a.size();\n\t\treturn max((a[n - 1] * a[n - 2] * a[n - 3]), (a[0] * a[1] * a[n - 1]));\n\t}\n};\n```\n\n**But Wait Can we do it in better than `O(nlogn)` ? `YES` \uD83D\uDE03**\n\n****\n### **2. Iterative Solution**\nIn this solution I store all required value in variable because don\'t want full sorted array for find answer but we only need 5 value `max1`, `max2`, `max3`, `min1` ans `min2` so we calculate that value by iteration\n**TC = O(n)\nSC = O(1)**\n```\nclass Solution {\npublic:\n\tint maximumProduct(vector<int>&a) {\n\t\tint max1 = INT_MIN, max2 = INT_MIN, max3 = INT_MIN;\n\t\tint min1 = INT_MAX, min2 = INT_MAX;\n\t\tint n = a.size();\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tif (a[i] > max1)\n\t\t\t{\n\t\t\t\tmax3 = max2;\n\t\t\t\tmax2 = max1;\n\t\t\t\tmax1 = a[i];\n\t\t\t}\n\t\t\telse if (a[i] > max2)\n\t\t\t{\n\t\t\t\tmax3 = max2;\n\t\t\t\tmax2 = a[i];\n\t\t\t}\n\t\t\telse if (a[i] > max3)\n\t\t\t{\n\t\t\t\tmax3 = a[i];\n\t\t\t}\n\n\t\t\tif (a[i] < min1)\n\t\t\t{\n\t\t\t\tmin2 = min1;\n\t\t\t\tmin1 = a[i];\n\t\t\t}\n\t\t\telse if (a[i] < min2)\n\t\t\t{\n\t\t\t\tmin2 = a[i];\n\t\t\t}\n\t\t}\n\t\treturn max((max1 * max2 * max3), (min1 * min2 * max1));\n\t}\n};\n```\n**If find helpful please upvote it \u2714**
[]