BEST SOLUTION FOR BEGINERS IN JAVA
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int maxProduct(int[] nums) {
        int firstMax=0;
        int secondMax=0;
        for(int i=0;i<nums.length;i++){
            if(nums[i]>=firstMax){
                secondMax=firstMax;
                firstMax=nums[i];
            }else if(nums[i]>=secondMax && nums[i]<=firstMax){  //[6,5,4,3,2,1] then the secondMax will be zero but thats wrong
                secondMax=nums[i];
            }
        }
        return (firstMax-1)*(secondMax-1);


        //If there exist negative Value too in the input Use this Method.

        // int firstMax=0;
        // int secondMax=0;
        // int firstMin=Integer.MAX_VALUE;
        // int secondMin=Integer.MAX_VALUE;
		// for(int i=0;i<nums.length;i++){
        //     if(nums[i]>=firstMax){
        //         secondMax=firstMax;
        //         firstMax=nums[i];
        //     }else if(nums[i]>=secondMax && nums[i]<=firstMax){
        //         secondMax=nums[i];
        //     }
            
        //     //Finding the Minimum for the same/
            
            
        //     if(nums[i]<=firstMin){
        //         secondMin=firstMin;
        //         firstMin=nums[i];
        //     }else if(nums[i]<=secondMin && nums[i]>=firstMin){
        //         secondMin=nums[i];
        //     }
        // }
        // // System.out.println("firstMax "+firstMax);
        // // System.out.println("SecondMax "+secondMax);
        // // System.out.println("firstMin "+firstMin);
        // // System.out.println("SecondMin "+secondMin);
        // // System.out.println("The maximum product value in the array is "+Math.max((firstMin*secondMin),(firstMax*secondMax)));
        // return Math.max(((firstMin-1)*(secondMin-1)),((firstMax-1)*(secondMax-1)));
    }
}
```
['Java']