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

You can find all his submissions for this problem from this link https://www.codechef.com/status/RAINBOWA?sort_by=All&sorting_order=asc&language=All&status=All&handle=piyush_kuma&Submit=GO no?? :stuck_out_tongue:

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.

Ok,thanks for the help!