The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:
- The MEX of is because does not belong to the array.
- The MEX of is because and belong to the array, but does not.
- The MEX of is because and belong to the array, but does not.
You're given an array containing integers where . Is it possible to reorder the elements of the array in such a way that the MEX of the first elements is equal to the MEX of the last elements?
Input Format
- The first line contains denoting the number of test cases. Then the test cases follow.
- The first line of each test case contains a single integer .
- The second line contains space-separated integers .
Output Format
For each test case, print YES
if there is a valid reordering of the given array and NO
otherwise.
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
2
0 0 0 1
2
0 0 1 1
3
1 3 2 3 3 2
3
0 0 1 1 1 2
Sample Output 1
NO
YES
YES
NO
Explanation
Test case : There is no way to reorder the elements of the array which satisfies the given conditions.
Test case : One possible reordering is . Here the MEX of the first half is MEX and the MEX of the second half is MEX.
Test case : The given array already satisfies the conditions. Here the MEX of the first half is MEX and the MEX of the second half is MEX
Solution:
No comments:
Post a Comment