#K6436. Reordering to Form an Arithmetic Progression
Reordering to Form an Arithmetic Progression
Reordering to Form an Arithmetic Progression
You are given several sequences of integers. For each sequence, determine whether it is possible to reorder the elements so that they form an arithmetic progression. An arithmetic progression is a sequence where the difference between consecutive terms is constant. Formally, a sequence (a_1, a_2, \dots, a_n) is an arithmetic progression if there exists a constant (d) such that for every (2 \le i \le n), (a_i - a_{i-1} = d).
Your task is to write a program that, for each test case, prints "YES" if the sequence can be rearranged into an arithmetic progression, and "NO" otherwise.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (T) representing the number of test cases. Each test case consists of a single line beginning with an integer (n) (the number of elements in the sequence) followed by (n) space-separated integers.
outputFormat
For each test case, output a single line containing either "YES" if the sequence can be rearranged to form an arithmetic progression, or "NO" otherwise. The output should be written to standard output (stdout).## sample
3
4 3 5 1 7
5 2 4 6 8 1
3 3 6 9
YES
NO
YES
</p>