My issue
Getting the Status
“Time Limit Exceeded”
while submitting the solution
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 p=0;p<n;p++)
{
int q,last;
//max=a.get(0);
last=a.get(a.size()-1);
for(q=a.size()-1;q>0;q--)
{
a.set(q,a.get(q-1));
}
a.set(0,last);
// System.out.println(a);
int sum=a.get(0)+a.get(n-1);
if(sum>=max)
max=sum;
}
System.out.println(max);
}
}
}
Learning course: Placement preparation using Java
Problem Link: CodeChef: Practical coding for everyone