#C1844. Minimum Difference Partitions

    ID: 45094 Type: Default 1000ms 256MiB

Minimum Difference Partitions

Minimum Difference Partitions

Given an array of integers, you are required to partition the array into exactly two non-empty subarrays. The goal is to minimize the difference between the maximum element of the first subarray and the minimum element of the second subarray. It turns out that if you sort the array and then choose a partition between two consecutive elements, this difference is exactly the difference between those two consecutive elements. Thus, the problem reduces to finding the minimum difference between any two consecutive elements in the sorted array.

Note: Each test case contains an array with at least two elements.

inputFormat

The first line of input contains an integer T denoting the number of test cases. For each test case, the first line contains an integer N representing the number of elements in the array. The second line contains N space-separated integers where each integer is an element of the array.

outputFormat

For each test case, output a single line containing the minimum difference between the maximum element of the first partition and the minimum element of the second partition, which is equivalent to the minimum difference between any pair of consecutive elements after sorting the array.

## sample
2
5
3 1 2 9 7
4
8 2 4 5
1

1

</p>