Code is not working for a specific test case

My code is not working for test case 5 i.e., abbaab. Please let me know where I am wrong.

Link to code CodeChef: Practical coding for everyone

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test = Integer.parseInt(br.readLine());
while(test–>0)
{
String input = br.readLine();
String left=“”, right=“”;
int len = input.length();
int mid = len/2;
if(len%2==0){
left = input.substring(0,mid);
right = input.substring(mid,len);
}
else{
left = input.substring(0,mid);
right = input.substring(mid+1,len);
}
int flag=0;
for(int i=0;i<left.length();i++)
{
loop2:
for(int j=0;j<right.length();j++)
{
if(i==left.length() || j==right.length())
break;
if(left.charAt(i)==right.charAt(j))
{
if(j==((right.length())-1))
right = right.substring(0,j) + “0”;
else if(j==0)
right = “0” + right.substring(j+1);
else
right = right.substring(0,j) + “0” + right.substring(j+1);
i++;
continue loop2;
}
if((j == (right.length()-1)) && (left.charAt(i)!=right.charAt(j)))
{
flag=1;
break;
}
}
}
if(flag==1)
System.out.println(“NO”);
else
System.out.println(“YES”);

	}
}

}

The link points to IDE :joy:

please check it now

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

I have attached a link. Please check it now