Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
507 B
1
Indexable
Never
public class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		
		while(t-->0){
		    int n=sc.nextInt();
		    int[] arr=new inr[n];
		    for(int i=0;i<n;i++){
		        arr[i]=sc.nextInt();
		    }
		    int r=solve(n,arr);
		    System.out.println(r);
		}
	}
	public int solve(int n,int[] arr){
	    int last=arr[n-1];
	    int max=0;
	    for(int i=0;i<n-1;i++){
	        max=Math.max(arr[i],max);
	        
	    }
	    return max+last;
	}
}
Leave a Comment