#K33367. Arithmetic Progression Rearrangement
Arithmetic Progression Rearrangement
Arithmetic Progression Rearrangement
You are given a sequence of integers. Your task is to determine whether the sequence can be rearranged to form an arithmetic progression.
An arithmetic progression is a sequence where the difference between consecutive elements is constant. In other words, after sorting the sequence, it should satisfy:
$$a_{i+1} - a_i = d \quad \text{for all } 1 \leq i < n $$If the sequence can be rearranged into such a progression, output YES
; otherwise, output NO
.
Note: You need to read the input from standard input and print the output to standard output.
inputFormat
The first line of the input contains a single integer T (T ≥ 1) — the number of test cases. The description of the test cases follows.
For each test case:
- The first line contains an integer N (N ≥ 2) — the number of elements in the sequence.
- The second line contains N space-separated integers representing the sequence.
outputFormat
For each test case, print a single line containing YES
if the sequence can be rearranged to form an arithmetic progression, or NO
otherwise.
3
3
3 1 2
4
2 4 1 3
4
1 2 4 5
YES
YES
NO
</p>