Most Efficient and Optimized || Fully Explained || O(n) || Java😊
\n# Approach :\n\n1. Scan the array and compute Maximum, second maximum and third maximum element present in the array.\n2. Scan the array and compute Minimum a
\n# Approach :\n\n1. Scan the array and compute Maximum, second maximum and third maximum element present in the array.\n2. Scan the array and compute Minimum and second minimum element present in the array.\n3. Return the maximum of product of Maximum, second maximum and third maximum and product of Minimum, second minimum and Maximum element.\n\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# Note:\n```\nStep 1 and Step 2 can be done in a single traversal \nof the array.\n```\n\n# Code (Explained in Comments)\n```\nclass Solution \n{\n    public int maximumProduct(int[] nums) \n    {\n        // Initialize Maximum, second maximum\n        // and third maximum element\n        int maxA=Integer.MIN_VALUE;\n        int maxB=Integer.MIN_VALUE;\n        int maxC=Integer.MIN_VALUE;\n\n        // Initialize Minimum and\n        // second minimum element\n        int minA=Integer.MAX_VALUE;\n        int minB=Integer.MAX_VALUE;\n        \n        for(int i=0;i<nums.length;i++)\n        {\n            // Update Maximum, second maximum\n            // and third maximum element\n            if(nums[i]>maxA)\n            {\n                maxC=maxB;\n                maxB=maxA;\n                maxA=nums[i];\n            }\n\n            // Update second maximum and\n            // third maximum element\n            else if(nums[i]>maxB)\n            {\n                maxC=maxB;\n                maxB=nums[i];\n            }\n\n            // Update third maximum element\n            else if(nums[i]>maxC)\n            {\n                maxC=nums[i];\n            }\n\n            // Update Minimum and second\n            // minimum element\n            if(nums[i]<minA)\n            {\n                minB=minA;\n                minA=nums[i];\n            }\n\n            // Update second minimum element\n            else if(nums[i]<minB)\n            {\n                minB=nums[i];\n            }\n        }\n        return Math.max(maxA*maxB*maxC,minA*minB*maxA);\n    }\n}\n```\n# *If you find this solution easy to understand and helpful, then please Upvote\uD83D\uDC4D\uD83D\uDC4D*
['Array', 'Math', 'Java']