What have I done wrong in this problem?On running, it’s giving the correct O/P but on submitting, it’s not.If anyone can get the error, please explain.
public static void main (String args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int a = new int[n];
for(int i=0; i<n; i++){
a[i] = sc.nextInt();
}
int maxi = Integer.MIN_VALUE;
for(int x : a){
if(x > maxi){
maxi = x;
}
}
int sum = 0;
for(int i=0; i<n; i++){
sum += a[i];
}
int ans = -1;
for(int i=2; i<=maxi; i+=2){
if(i*n == sum){
ans = i;
break;
}
}
if(ans != -1){
System.out.println(“Yes”);
}
else{
System.out.println(“No”);
}
}
}