My issue
The answer is correct but I get the message as time limit exceeded and answer not getting submitted
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 maxSum = Integer.MIN_VALUE;
for (int j = 0; j < n; j++) {
int sum = a.get(0) + a.get(a.size() - 1); // Calculate A1 + AN for the current rotation
maxSum = Math.max(maxSum, sum); // Update maxSum if the current sum is greater
Collections.rotate(a, 1); // Right rotate the array by 1
}
System.out.println(maxSum);
}
}
}
Learning course: Placement preparation using Java
Problem Link: CodeChef: Practical coding for everyone