Xor Palindrome solution codechef

Xor Palindrome solution codechef

 

SOLUTION:- CLICK HERE

 

A (11-indexed) binary string SS of length NN is called a xor palindrome if the value of SiS(N+1i)Si⊕S(N+1−i) is the same for all 1iN1≤i≤N.

For example, 0011111111 and 01010101 are xor palindromes, while 11101110 and 110101110101 are not.

You are given a binary string SS of length NN. Determine if it is possible to rearrange it to form a xor palindrome or not.

Input Format

  • The first line of input contains a single integer TT — the number of test cases. The description of TT test cases follows.
  • The first line of each test case contains an integer NN — the length of the binary string SS.
  • The second line of each test case contains the binary string SS containing 00s and 11s only.

Output Format

For each test case, output YESYES if it is possible to rearrange SS to convert it into a xor palindrome. Otherwise output NONO.

You may print each character of YESYES and NONO in uppercase or lowercase (for example, yesyesyEsyEsYesYes will be considered identical).

Constraints

  • 1T10001≤T≤1000
  • 1N1051≤N≤105
  • SS is a binary string, i.e, contains only the characters 00 and 11
  • It is guaranteed that the sum of NN over all test cases does not exceed 21052⋅105.

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input 1 

4
2
00
4
0011
3
001
4
0001

Sample Output 1 

YES
YES
YES
NO

Explanation

Test case 110000 is already a xor palindrome. [The value of SiS(N+1i)Si⊕S(N+1−i) is 00 for all 1iN1≤i≤N.]

Test case 2200110011 is already a xor palindrome. [The value of SiS(N+1i)Si⊕S(N+1−i) is 11 for all 1iN1≤i≤N.]

Test case 33001001 can be rearranged to form 010010 which is a xor palindrome. [The value of SiS(N+1i)Si⊕S(N+1−i) is 00 for all 1iN1≤i≤N.]

Test case 44: It can be proved that 00010001 can not be rearranged to form a xor palindrome.

SOLUTION:- CLICK HERE

Leave a Comment

Your email address will not be published.