Begineer Friendly || O(nlogn) -> O(n)
IDEA : Product is going to be maximum if we take product of top 3 maximum number. and also negative*negative became Positive so we will also consider a combinat
IDEA : Product is going to be maximum if we take product of top 3 maximum number. and also **negative*negative became Positive** so we will also consider a combination of 2 most negative with maximum .\nanswer = Math.max(max1*max2*max3,max1*min1*min2)\n**min1:** minimum element of array\n**min2:** 2nd minimum element of array \n**max1**: maximum element of array\n**max2:** 2nd maximum element of array\n**max3:** 3rd maximum of array \n\n**Solution 1: Sorting**\n```\n public int maximumProduct(int[] nums) {\n        Arrays.sort(nums);\n        int min1=nums[0];\n        int min2=nums[1];\n        \n        int max1=nums[nums.length-1];\n        int max2=nums[nums.length-2];\n        int max3=nums[nums.length-3];\n        \n        int c1=max1*(max2*max3);\n        int c2=min1*(min2*max1);\n        \n        return Math.max(c1,c2);\n    }\n```\n**Time:O(nlogn) and Space:O(1)**\n\n**Solution 2: Effective Solution** \n```\npublic int maximumProduct(int[] nums) {\n        int max1=Integer.MIN_VALUE;\n        int max2=Integer.MIN_VALUE;\n        int max3=Integer.MIN_VALUE;\n        \n        int min1=Integer.MAX_VALUE;\n        int min2=Integer.MAX_VALUE;\n        \n        for(int val:nums){\n            \n            if(val>max1){\n                max3=max2;\n                max2=max1;\n                max1=val;\n            }else if(val>max2){\n                max3=max2;\n                max2=val;\n            }else if(val>max3){\n                max3=val;\n            }\n            \n            if(val<min1){\n                min2=min1;\n                min1=val;\n            }else if(val<min2){\n                min2=val;\n            }\n        }\n        \n        return Math.max(max1*max2*max3,min1*min2*max1);    \n    }\n```\t\n**Time:O(N) && Space:O(1)**\n\n##### Advice for you : Before proceeding to solution confirm your interviewer that array is containing negative values or not?.. If you didn\'t ask these clarification question then even after solving it in most optmised way you may get rejection..\n##### Don\'t Assume anything by yourself in interview\n\nSimilar Question : [Largest number atleast twice of others](https://leetcode.com/problems/largest-number-at-least-twice-of-others/)\n\nPlease **Upvote** if found it helpful:)\n\t
[]