#K66802. Reordering Array for Consecutive Differences

    ID: 32501 Type: Default 1000ms 256MiB

Reordering Array for Consecutive Differences

Reordering Array for Consecutive Differences

Given an array of integers, determine whether it is possible to reorder its elements so that each adjacent pair of elements has a difference of exactly 1. In other words, after reordering, the array should form a consecutive sequence. Note that if the array has only one element, it trivially meets the requirement.

For each test case, output a single line with either "YES" if such a reordering is possible, or "NO" otherwise.

inputFormat

The first line contains an integer T, the number of test cases. Each test case consists of two lines. The first line contains an integer N representing the number of elements in the array. The second line contains N space-separated integers.

outputFormat

For each test case, print one line containing "YES" if the array can be reordered to form a consecutive sequence (i.e. every adjacent pair has a difference of exactly 1), or "NO" otherwise.

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

NO YES YES NO

</p>