#K36737. Maximize Array Range After One Swap
Maximize Array Range After One Swap
Maximize Array Range After One Swap
Given an array of integers, you are allowed to perform exactly one swap operation (i.e. exchange two distinct elements) to maximize the range of the array. The range of an array is defined as:
\( \text{Range} = \max(A) - \min(A) \)
Your task is to output the maximum possible range that can be achieved for each test case after performing exactly one swap.
Note: Even if the array already has the maximum range, you still must perform one swap (which may not change the range).
inputFormat
The input is read from standard input and has the following format:
- The first line contains a single integer \( T \) denoting the number of test cases.
- For each test case, the first line contains an integer \( n \), the number of elements in the array.
- The next line contains \( n \) space-separated integers representing the elements of the array.
outputFormat
For each test case, output a single integer on a new line --- the maximum possible range (i.e. \( \max(A) - \min(A) \)) after performing exactly one swap operation.
## sample3
4
1 5 3 7
3
-5 -15 5
5
1 2 3 4 5
6
20
4
</p>