forked from PrajaktaSathe/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXorpalindrome.java
45 lines (42 loc) · 1 KB
/
Xorpalindrome.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//code for xorpalindrome in Java
import java.util.*;
import java.lang.*;
import java.io.*;
class Xorpalindrome
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
int t=Integer.parseInt(br.readLine());
StringBuffer sb=new StringBuffer();
while(t-->0)
{
int n=Integer.parseInt(br.readLine());
String s=br.readLine();
int count1=0,count2=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='1')
count1++;
else
count2++;
}
boolean flag=false;
if(n%2==0)
{
if(count1==count2||count1%2==0&&count2%2==0)
flag=true;
}
else
{
flag=true;
}
if(flag)
System.out.println("YES");
else
System.out.println("NO");
}
}
}