CF2191B MEX Reordering
Description
You are given an integer array $ a $ consisting of $ n $ elements. Denote $ f(l, r) = \operatorname{MEX}([a_l, a_{l + 1}, \ldots, a_r]) $ $ ^{\text{∗}} $ .
Determine if there is a way to reorder the array $ a $ such that for every $ i $ ( $ 1 \le i \le n - 1 $ ), $ f(1, i) \neq f(i + 1, n) $ . In other words, for every split point $ i $ , the $ \operatorname{MEX} $ of the prefix must be different from the $ \operatorname{MEX} $ of the suffix.
$ ^{\text{∗}} $ The minimum excluded (MEX) of a collection of integers $ c_1, c_2, \ldots, c_k $ is defined as the smallest non-negative integer $ x $ which does not occur in the collection $ c $ .
Input Format
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 500 $ ). The description of the test cases follows.
The first line of each test case contains a single integer $ n $ ( $ 2 \le n \le 100 $ ) — the length of the array.
The second line of each test case contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 0 \le a_i \le n $ ).
Output Format
Output "YES" if you can reorder $ a $ so that the condition from the statement is satisfied, and "NO" otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Explanation/Hint
In the first example, the initial ordering of $ a $ already satisfies the condition. The only choice for $ i $ is $ i = 1 $ . Then $ f(1, i) = f(1, 1) = \operatorname{MEX}([a_1]) = \operatorname{MEX}([1]) = 0 $ , and $ f(i + 1, n) = f(2, 2) = \operatorname{MEX}([a_2]) = \operatorname{MEX}([0]) = 1 $ . Since $ 0 \neq 1 $ , the condition is satisfied.
In the second example, it can be shown that there is no way to reorder $ a $ to satisfy the condition. As an example, consider the order $ a = [3, 0, 0] $ and $ i = 2 $ . We have $ f(1, i) = f(1, 2) = \operatorname{MEX}([a_1, a_2]) = \operatorname{MEX}([3, 0]) = 1 $ , and $ f(i + 1, n) = f(3, 3) = \operatorname{MEX}([a_3]) = \operatorname{MEX}([0]) = 1 $ , hence $ f(1, i) = f(i + 1, n) $ , so the choice of reordering is invalid.
In the third example, we can reorder $ a $ into $ [1, 6, 1, 0, 0, 5] $ . When $ i = 4 $ , $ f(1, i) = f(1, 4) = \operatorname{MEX}([a_1, a_2, a_3, a_4]) = \operatorname{MEX}([1, 6, 1, 0]) = 2 $ , $ f(i + 1, n) = f(5, 6) = \operatorname{MEX}([a_5, a_6]) = \operatorname{MEX}([0, 5]) = 1 $ , so the condition is satisfied for this $ i $ . It can be verified that the condition is also satisfied for all other $ i $ .