AP or Not

3.4

7 votes
Sorting, Basic Programming, Easy, Mathematics, Open, Approved, Mathamatics
Problem

Bob and Khatu are best friends. One Bob asked Khatu to solve a problem. He gave him an array of integers and asked him to tell him if he can arrange elements in the array such that the array forms a special sequence.
A special sequence is a sequence in which every two consecutive elements have same difference.
Since Khatu is good at solving problems he solved it within 1 minute. Now its time for you to solve the problem.

Input:
First line of input contains number of test cases T. Each test case contains two lines. First line contains value of N, size of Array. Next line contains N elements separated by space.

Output:
For each test case print YES if it is possible to arrange elements of array such that array form a special sequence else print NO.

Constraints:
1 ≤ T ≤ 5
3 ≤ N ≤ 105
0 ≤ Ai ≤ 109

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?