Dazzling Even-Odd Challenge CodeChef Solution | CodeChef Problem Solution 2022
Dazzler has an interesting task for you.
You will be given an array of positive integers such that:
- is always even.
- Exactly elements in the array are even and elements are odd.
In one operation, you should do the following steps:
- Choose two different indices and .
- Set .
- Set .
You need to apply some finite (possibly zero) number of operations on the array such that:
- The parity of the final element at each index is same as the parity of the initial element at that index. For example, if the element in the initial array is even, then, the element in the final array must be even as well.
- All the odd elements in the final array are equal.
- All the even elements in the final array are equal.
Print YES
if it is possible to meet all the above conditions after doing some finite (possibly zero) number of operations. Otherwise, print NO
.
Input Format
- First line will contain , number of test cases. Then the test cases follow.
- First line of each test case contains , number of elements in the array . Note that, is even.
- Second line of each test case contains space-separated positive integers, the elements of the array.
Output Format
For each test case, output in a single line, YES
if it is possible to meet all the given conditions after doing some finite (possibly zero) number of operations. Otherwise, print NO
.
You may print each character of the string in uppercase or lowercase (for example, the strings YeS
, yEs
, yes
and YES
will all be treated as identical).
Constraints
- Sum of over all test cases does not exceed .
Sample Input 1
4
4
1 1 2 4
4
1 2 5 6
2
1 2
4
1 2 3 4
Sample Output 1
NO
YES
YES
YES
Explanation
Test case : It is not possible to satisfy all the given conditions using any number of operations.
Test case : One of the possible sequence of operations is listed below:
- In the first operation, choose and . Thus, and . The array will become .
- In the second operation, choose and . Thus, and . The array will become .
- In the third operation, choose and . Thus, and . The array will become .
- In the fourth operation, choose and . Thus, and . The array will become .
Here, all the odd elements are equal and all the even elements are equal. Also, the parity at each index is preserved.
Test case : The array satisfies all the conditions. Thus, operations are needed.
Join Now for Solution:-
No comments:
Post a Comment