Three different approaches || Beats 100%
Intuition\nThe problem requires finding the maximum product of two distinct elements in an array after reducing each by 1. The first thought is to find the two 
# Intuition\nThe problem requires finding the maximum product of two distinct elements in an array after reducing each by 1. The first thought is to find the two largest elements in the array, as they will maximize the product.\n\n# Approach\nFirst Approach (Bubble Sort):\n\nSort the array in non-decreasing order using a custom bubble sort and return the product of the two largest elements, reduced by 1 each.\nThis approach works but is inefficient for large arrays due to its \nO(n^2)complexity.\n\nSecond Approach (Built-in Sort):\n\nSort the array using Arrays.sort(), which has O(nlogn) complexity, and then return the product of the two largest elements (last two elements in the sorted array) minus 1 each.\nThis is more efficient than the bubble sort but still involves sorting.\n\nOptimized Approach (Single Pass):\n\nUse a single pass through the array to find the two largest elements, max1 and max2, by updating them as we traverse the array.\nReturn (max1\u22121)\xD7(max2\u22121).\nThis approach is the most efficient, with a time complexity of \nO(n), as it only requires a single traversal.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```java []\nclass Solution {\n    public int maxProduct(int[] nums) {\n\n        // first way:- \n\n\n        // boolean isSorted;\n        // for (int i = 0; i<nums.length;i++) {\n        //     isSorted = false;\n        //     for (int j = 1; j < nums.length-i;j++) {\n        //         if (nums[j] < nums[j-1]) {\n        //             int temp = nums[j];\n        //             nums[j] = nums[j-1];\n        //             nums[j-1] = temp;\n\n        //             isSorted = true;\n        //         }\n        //     }\n        //     if (isSorted == false) {\n        //         return ((nums[nums.length-1]-1)*(nums[nums.length-2]-1));\n        //     }\n        // }\n        // return ((nums[nums.length-1]-1)*(nums[nums.length-2]-1));\n\n\n        // second way:-\n\n\n        // Arrays.sort(nums);\n        // return ((nums[nums.length-1]-1)*(nums[nums.length-2]-1));\n\n\n        // third way:-\n\n        int max1 = Integer.MIN_VALUE;\n        int max2 = Integer.MIN_VALUE;\n\n        for (int num : nums) {\n            if(num >= max1) {\n                max2 = max1;\n                max1 = num;\n            } else if (num > max2) {\n                max2 = num;\n            }\n        }\n        return ((max1-1)*(max2-1));\n    }\n}\n```
['Java']