I am an aspiring coder. I have been trying to solve this question on codechef. What do you reckon is the problem here? A link to the question: https://www.codechef.com/submit/EVENTUAL?tab=statement My code fail when the input is 990, which, in the question refers to the value of n. The value of 'n' refers to the length of the string. My code for the question has been provided below.
import java.util.Scanner;
public class eventual_reduction {
public static void main(String[] args) {
try (Scanner in = new Scanner(System.in)) {
int t = in.nextInt();
while(t-->0){
long count =0;
long n = in.nextInt();
String str = in.next();
if(n%2!=0){
System.out.println("NO");
}else{
String s = str;
for(int i=0; i<n; i++){
if(s.charAt(0)==str.charAt(i)){
count++;
if((count+1)%2==0){
for(int j=1; j<n;j++){
if(s.charAt(j)==str.charAt(i)){
count++;
}
}
}
}
}
if(count%2==0){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}
}
}
Could you please help me out with the code? Would love to see ways to improve my code. Thank you!