Contents
Equal Difference solution codechef

For Solution
Click Here!
You are given an array of NN integers. Find the minimum number of integers you need to delete from the array such that the absolute difference between each pair of integers in the remaining array will become equal.
Input Format Equal Difference solution codechef
 The first line of input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
 The first line of each test case contains an integer NN.
 The second line of each test case contains NN spaceseparated integrs A1,A2,…,ANA1,A2,…,AN.
Output Format
For each test case, print a single line containing one integer – the minimum number of integers to be deleted to satisfy the given condition.
Constraints
 1≤T≤1041≤T≤104
 1≤N≤1051≤N≤105
 1≤Ai≤1091≤Ai≤109
 Sum of NN over all test cases does not exceed 5⋅1055⋅105.
Sample Input 1
3
2
1 2
5
2 5 1 2 2
4
1 2 1 2
Sample Output 1 Equal Difference solution codechef
0
2
2
Explanation
Test case 11: There is only one pair of integers and the absolute difference between them is A1−A2=1−2=1A1−A2=1−2=1. So there is no need to delete any integer from the given array.
Test case 22: If the integers 11 and 55 are deleted, the array A becomes [2,2,2][2,2,2] and the absolute difference between each pair of integers is 00. There is no possible way to delete less than two integers to satisfy the given condition.

For Solution
Click Here!