#C11420. Minimum Adjacent Weight Difference
Minimum Adjacent Weight Difference
Minimum Adjacent Weight Difference
You are given several test cases. In each test case, you are given an integer \(n\) and a list of \(n\) integers representing the weights of books. Your task is to compute the minimum possible difference between any two adjacent weights after sorting the list in non-decreasing order.
More formally, given a sorted list of weights \(w_1 \le w_2 \le \cdots \le w_n\), find
[ \min_{1 \le i < n} {w_{i+1} - w_i} ]
If a test case contains only one weight (i.e. (n = 1)), output inf
(infinity) as there is no pair to compare.
Example:
- For \(n = 3\) with weights [3, 2, 1], after sorting the list becomes [1, 2, 3] and the minimum adjacent difference is \(2-1 = 1\).
inputFormat
The input begins with an integer \(T\) denoting the number of test cases. Each test case consists of:
- An integer \(n\) representing the number of books.
- A line with \(n\) space-separated integers representing the weights of the books.
Input is read from standard input (stdin).
outputFormat
For each test case, output a single line containing the minimum difference between any two adjacent weights after sorting. If there is only one weight in the test case, output inf
. Output is written to standard output (stdout).
4
3
3 2 1
4
4 1 3 2
3
5 5 5
4
1 100 500 1000
1
1
0
99
</p>