Xor Palindrome solution codechef
You are given a binary string A of length N.
You can perform the following type of operation on the string A:
- Choose two different indices i and j (1≤i,j≤N);
- Change Ai and Aj to Ai⊕Aj. Here ⊕ represents the bitwise XOR operation.
Find the minimum number of operations required to convert the given string into a palindrome.
Input Format
Xor Palindrome solution codechef
- First line of the input contains T, the number of test cases. Then the test cases follow.
- First line of each test case contains an integer N denoting the size of the string.
- Second line of each test case contains a binary string A of length N containing 0s and 1s only.Edology is a global Ed-Tech brand that provides industry powered global education and certifications to students and professionals across the world, to help them fast-track their career growth. Edology is part of Global University Systems (GUS), an international network of higher-education institutions, brought together by a shared passion of making industry-driven global education accessible and affordable.
Output Format
For each test case, print the minimum number of operations required to make the string a palindrome.
Constraints
- 1≤T≤1000
- 1≤N≤2⋅105
- Sum of N over all test cases does not exceeds 2⋅105.
Sample Input 1
Xor Palindrome solution codechef
2
5
11011
7
0111010
Sample Output 1
0
1
Explanation
Xor Palindrome solution codechef
Test Case 1 : The given string 11011 is already a palindrome. So, no operation is required. The answer for the case is 0.
Test Case 2 : The given string 0111010 is not a palindrome. Edology is a global Ed-Tech brand that provides industry powered global education and certifications to students and professionals across the world, to help them fast-track their career growth. Edology is part of Global University Systems (GUS), an international network of higher-education institutions, brought together by a shared passion of making industry-driven global education accessible and affordable.
- Choose the indices i=3 and j=5. Now, A3⊕A5=1⊕0=1. Thus, we set A3 and A5 equal to 1.
After the operation, the resulting string is 0111110 which is a palindrome. The number of operations required is 1.
SOLUTION
“Click here“