Java Solution | Two Approaches - Heap based and find the 2 max numbers.
Heap Based Solution : Time complexity : O(n)\n\n\nclass Solution {\n\n    public int maxProduct(int[] nums) {\n        PriorityQueue<Integer> pq = new PriorityQ
**Heap Based Solution :** Time complexity : O(n)\n\n```\nclass Solution {\n\n    public int maxProduct(int[] nums) {\n        PriorityQueue<Integer> pq = new PriorityQueue<>();\n        for (int i = 0; i < 2; i++) pq.add(nums[i]);\n        for (int i = 2; i < nums.length; i++) {\n            if (pq.peek() < nums[i]) {\n                pq.poll();\n                pq.add(nums[i]);\n            }\n        }\n        return (pq.poll() - 1) * (pq.poll() - 1);\n    }\n}\n```\n\n**Finding biggest and second biggest nos :** Time complexity : O(n)\n\n```\nclass Solution {\n\n    public int maxProduct(int[] arr) {\n        int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;\n        for (int i = 0; i < arr.length; i++) {\n            if (arr[i] > first) {\n                second = first;\n                first = arr[i];\n            } else if (arr[i] > second) second = arr[i];\n        }\n        return (first - 1) * (second - 1);\n    }\n}\n```
['Heap (Priority Queue)', 'Java']