#K58402. Minimum Difference Between Student Heights

    ID: 30634 Type: Default 1000ms 256MiB

Minimum Difference Between Student Heights

Minimum Difference Between Student Heights

You are given the heights of a group of students. Your task is to rearrange the students (if necessary) so that the absolute difference between the heights of any two consecutive students is minimized. In other words, after optimally reordering the list, you should find the minimum absolute difference between any two adjacent heights.

Note: Although one might think that rearranging can affect all adjacent differences, it turns out that simply sorting the list yields the optimal arrangement for determining the minimum gap.

For example, given the heights [4, 2, 5], sorting them gives [2, 4, 5] and the adjacent differences are [2, 1], so the minimum difference is 1.

inputFormat

The first line of input contains an integer T representing the number of test cases.

For each test case, the first line contains an integer N denoting the number of students, followed by a line with N space-separated integers representing the heights of the students.

Example:

2
3
4 2 5
5
10 1 14 9 2

outputFormat

For each test case, output a single line with the minimum absolute difference between the heights of any two consecutive students after the optimal rearrangement (which is achieved by sorting the list).

Example:

1
1
## sample
2
3
4 2 5
5
10 1 14 9 2
1

1

</p>