error in RAINBOWA

Now what’s wrong in this?

import java.util.*;
class Codechef
{
public static void main (String[] args)
{
Codechef ob=new Codechef();
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int o=0;o<t;o++){
int n=sc.nextInt();
int a[]=new int [n];
for (int i=0;i<n;i++ )
a[i]=sc.nextInt();
int m=n/2,l=0,u=n-1;
boolean f=true;
while (l!=m){
if ((a[l++]!=a[u–]))
f=false;

	    }
	    if (a[m]!=7)
	        f=false;
	    if (f)
	        System.out.println("Yes");
	    else 
	        System.out.println("No");
	}
    
}

}

code link please

Your code is giving ArrayIndexOutOfBoundsException for this input.

1

9

4 9 4 10 7 7 8 1 6

while (l!=m){
if ((a[l]!=a[u]))
f=false;
else
l++;
u–;
}

This is your faulty piece of code. You are not always increasing the value of l, instead you are increasing it only when you get a match. Thus, if all the elements are different, then value of l will never increase and your loop will never terminate. Thus, NZEC.

You can find all his submissions for this problem from this link CodeChef: Practical coding for everyone no?? :stuck_out_tongue:

Ok,thanks for the help!