#C4870. Consecutive Sequence Check

    ID: 48456 Type: Default 1000ms 256MiB

Consecutive Sequence Check

Consecutive Sequence Check

Given an integer \(t\) representing the number of test cases, you are provided with \(t\) test cases. In each test case, the first input is an integer \(n\) indicating the number of elements in the array, followed by \(n\) integers. Your task is to determine whether the numbers in each array can be rearranged to form a consecutive sequence.

A sequence is considered consecutive if, after sorting, the difference between every pair of adjacent elements is exactly 1, that is, for a sorted sequence \(a_1, a_2, \dots, a_n\), the condition \(a_{i+1} - a_i = 1\) holds for all \(1 \leq i < n\). Note that an empty array (when \(n = 0\)) is trivially considered to form a consecutive sequence.

inputFormat

The input is given via stdin and has the following format:

\(t\)
\(n_1\)
\(a_{1,1} a_{1,2} ... a_{1,n_1}\)
\(n_2\)
\(a_{2,1} a_{2,2} ... a_{2,n_2}\)
... 

Here, the first line contains an integer \(t\), the number of test cases. For each test case, the first line contains an integer \(n\) denoting the number of elements in the array. The next line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

For each test case, output a single line to stdout containing either "YES" if the array can be rearranged to form a consecutive sequence, or "NO" otherwise.

## sample
3
5
4 2 1 3 5
4
1 2 4 5
3
8 7 9
YES

NO YES

</p>