#C9805. Maximum Beauty of Array Subset
Maximum Beauty of Array Subset
Maximum Beauty of Array Subset
You are given T test cases. For each test case, you are provided an integer N and an array of N integers. Your task is to compute the maximum beauty of a subset of the array that contains at least two elements. The beauty for any subset is defined as:
\(\text{beauty} = 2 \times (\max - \min)\)
In other words, the maximum beauty can be obtained by selecting the smallest and the largest number in the array.
Note: It is guaranteed that each test case contains at least two numbers.
inputFormat
The input is read from the standard input (stdin) and has the following format:
- The first line contains a single integer T, the number of test cases.
- Then for each test case:
- The first line contains a single integer N, the number of elements.
- The second line contains N space-separated integers representing the array.
outputFormat
For each test case, output the maximum possible beauty as defined above on a separate line. The output is printed to the standard output (stdout).
## sample2
3
1 4 7
4
-2 0 2 3
12
10
</p>