My issue
int max=0;
for(int j=0;j<n;j++){
int temp=a.get(n-1);
for(int k=n-2;k>=0;k–){
int z=a.get(k);
a.set(k+1,z);
}
a.set(0,temp);
max=Math.max(a.get(0)+a.get(n-1),max);
}
System.out.println(max);
}
i did try to rotate as mentioned in the question
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
int max=0;
for(int j=0;j<n;j++){
int temp=a.get(n-1);
for(int k=n-2;k>=0;k--){
int z=a.get(k);
a.set(k+1,z);
}
a.set(0,temp);
max=Math.max(a.get(0)+a.get(n-1),max);
}
System.out.println(max);
}
}
}
Learning course: Placement preparation using Java
Problem Link: CodeChef: Practical coding for everyone