#K6161. Consecutive Sequence Reordering
Consecutive Sequence Reordering
Consecutive Sequence Reordering
You are given an array of integers. Your task is to determine whether it is possible to reorder the array such that the integers form a consecutive sequence. In other words, after reordering, for every adjacent pair \(a_{i-1}\) and \(a_i\), the absolute difference should be exactly one: \( |a_i - a_{i-1}| = 1 \). Each test case begins with an integer denoting the number of elements, followed by the array elements. You may assume that all numbers in the array are unique.
inputFormat
The input is read from standard input (stdin) and is structured as follows:
- The first line contains a single integer \(T\) representing the number of test cases.
- For each test case, the first line contains an integer \(n\) which is the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
For each test case, output a single line to standard output (stdout) with the answer "YES" if the array can be reordered to form a consecutive sequence, or "NO" otherwise.
## sample3
3
1 3 2
5
4 2 9 6 3
4
7 8 6 10
YES
NO
NO
</p>