Palindrome lover

3.6

11 votes
Bitmask, Basics of Bit Manipulation, Basic Programming, Bit Manipulation, Bit manipulation, Basics of bit manipulation
Problem

Given an array of N integers

You have to transform the array, for every i(1iN): a[i]=a[i]%2

For example: if the given array is 3,4,5 then after the transformation the array will be 1,0,1


Your task is to convert the array into a palindrome and for that you can re-arrange the elements however you wish

Is it possible to convert the array into a palindrome?


Input :
The first line contains T, the number of test cases 1T103
The second line contains N, the number of array elements 1N105
The third line contains N integers, the array elements 1a[i]109


Output:
For all test cases print 1 if the array can be converted into a palindrome or else print 0

Sample Input
2
3 
1 5 7
6
1 2 3 3 3 3
Sample Output
1
0
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For test case 1, the array will be transformed into 1,1,1 after mod with 2,
The array is already a palindrome, so the output is 1

For test case 2, the array after transformation will be 1,0,1,1,1,1

Now no matter how you try to arrange them, it is impossible to convert the array into a palindrome,that's why the output is 0

Editor Image

?