C++ Optimized Solution | 4 line Code | beginner level | BEATS 100%
IntuitionThe problem requires finding the two largest numbers in the array and computing their modified product (max1−1)×(max2−1).Instead of sorting, we can eff
# Intuition
The problem requires finding the two largest numbers in the array and computing their modified product ***(max1−1)×(max2−1)***.

Instead of sorting, we can efficiently track the two largest numbers while iterating through the array.

# Approach
1. Initialize max1 and max2 to the smallest possible integer values.
2. Traverse the array:
    -   If the current element is greater than max1, update max2 to store the previous max1, and assign max1 to the current element.
    -   Else if the current element is greater than max2, update max2 with the current element.
3. Compute the result using (max1−1)×(max2−1).

This approach ensures we find the two largest numbers in a single pass.

# Complexity
- Time complexity:

O(n) — We iterate through the array once

- Space complexity:

O(1) — We use only a few integer variables, regardless of input size.

# Code
```cpp []
class Solution {
public:
    int maxProduct(vector<int>& nums) {
        int max1 = INT_MIN;
        int max2 = INT_MIN;
        for(int i=0 ; i<nums.size() ; i++){
            if(nums[i]>max1){
                max2 = max1;
                max1 = nums[i];
            }
            else if(nums[i]>max2 ){
                max2 = nums[i];
            }
        }
        int ans = (max1-1)*(max2-1) ;
        return ans;
    }
};
```
['Array', 'Sorting', 'C++']