My issue
my method produced right output but when i hit submit it shows me that it’s a wrong answer
My code
import java.util.*;
class Codechef
{
public static void main (String[] args)
{
Scanner read = new Scanner(System.in);
int t = read.nextInt();
for(int i=0; i<t; i++)
{
ArrayList<Integer> a = new ArrayList<Integer>();
int n = read.nextInt();
for(int j=0; j<n; j++){
int ele = read.nextInt();
a.add(ele);
}
// Update your code below this line to solve the problem
ArrayList<Integer> b = new ArrayList<Integer>();
for(int l=0; l<n; l++){
if(l==(n-1)){
b.add(0, a.get(l));
}
else{
b.add(l, a.get(l));
}
}
System.out.println(b.get(0)+b.get(b.size()-1));
}
}
}
Learning course: Placement preparation using Java
Problem Link: Practice Problem in - CodeChef