O(NlogN) ➡️O(N) ||Beats 100% || Two Java Approaches
Approach\nSort the array: so three max numbers are in the end of the array, two negative numbers whose product will be max will be on the start of the array.\n 
# Approach\n**Sort the array:** so three max numbers are in the end of the array, two negative numbers whose product will be max will be on the start of the array.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(N*logN)$$\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 {\n    public int maximumProduct(int[] nums) {\n        Arrays.sort(nums);\n        int case1 = nums[0]*nums[1]*nums[nums.length-1];\n        int case2 = nums[nums.length-1]*nums[nums.length-2]*nums[nums.length-3];\n\n        int maxProduct = Integer.max(case1, case2);\n        return maxProduct;\n    }\n}\n```\n# Approach\nFind max1, max2, max3, min1 and min2 using a for loop\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\n# Code\n```\n    public int maximumProduct(int[] nums) {\n        int min1, min2, max1, max2, max3;\n        min1 = min2 = Integer.MAX_VALUE;\n        max1 = max2 = max3 = Integer.MIN_VALUE;\n        for(int i = 0; i < nums.length; i++){\n            //Updating maximums\n            if(max1 < nums[i]){\n                max3 = max2;\n                max2 = max1;\n                max1 = nums[i];\n            }else if(max2 < nums[i]){\n                max3 = max2;\n                max2 = nums[i];\n            }else if(max3 < nums[i]){\n                max3 = nums[i];\n            }\n            \n            //Updating minimums\n            if(min1 > nums[i]){\n                min2 = min1;\n                min1 = nums[i];\n            }else if(min2 > nums[i]){\n                min2 = nums[i];\n            }\n            \n        }\n        \n        return Math.max(max1 * max2 * max3 , min1 * min2 * max1);\n    }\n```
['Java']