Given an array of integers, the array will be balanced if you can select at least one index and divide the array into two non empty subarrays, and such that .
for the subarray is defined as the difference between the maximum and the minimum element of . For example if , then .
Before dividing the array, you can do one type of operation to the array any number of times(possibly zero). Select any index () and any integer () and set = .
You need to output the minimum number of operations required to make the array balanced. It is guaranteed that any array can be made balanced under the given constraints by applying a finite number of operations.
The input contains multiple test cases. The first line of input contains one integer () the number of test cases.
The first line of each test case contains one integer () the size of the array.
The second line of each test case contains integers , , …, ().
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print one integer — the minimum number of operations required to make the array balanced.
Input | Output |
---|---|
2 2 12 12 6 1 3 6 10 6 4 | 0 1 |
For the first test case, the array is already Balanced. For the second test case, we can do one operation to make the array Balanced. We can select and and set . Then the array will be . We can select index to divide the array into two subarrays, and . . . So the array is Balanced. |