GeeksforGeeks/Java/Medium/Container With Most Water/container-with-most-water.java
<reponame>AyushAgnihotri2025/CP-Solutions//{ Driver Code Starts
//Initial Template for Java


import java.io.*;
import java.util.*;
import java.lang.*;


class GFG {
	public static void main (String[] args) throws IOException{
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine().trim()); //Inputting the testcases
		while(t-->0){
		    int n = Integer.parseInt(br.readLine()); // input size of array
		    int arr[] = new int[n];
		    String inputLine[] = br.readLine().trim().split("\\s+");
		    for(int i=0; i<n; i++){
		        arr[i] = Integer.parseInt(inputLine[i]); // input elements of array
		    }
		    Solve T = new Solve();
            long ans = T.maxArea(arr,n);
            System.out.println(ans);
		}
	}
}

// } Driver Code Ends


//User function Template for Java


class Solve{
    
    long maxArea(int A[], int len){
        // Code Here
        long ans=0;
        int left=0;
        int right=A.length-1;
        while(left<right){
            int area=(right-left)*Math.min(A[left],A[right]);
            ans=Math.max(area,ans);
            if(A[left]<A[right]) left++;
            else if(A[right]<A[left]) right--;
            else{
                left++;
                right--;
            }
        }
        return ans;
    }
}