#C4619. Minimum Subarray Sorting
Minimum Subarray Sorting
Minimum Subarray Sorting
Given an integer array \( arr \) of size \( n \), your task is to find the minimum length of a contiguous subarray that, when sorted, makes the entire array sorted in non-decreasing order.
In other words, determine indices \( L \) and \( R \) (with \( 0 \le L \le R < n \)) such that if the subarray \( arr[L \ldots R] \) is sorted, then the whole array becomes sorted. If the array is already sorted, you should output 0.
For example, if \( arr = [1, 3, 2] \), sorting the subarray \( [3, 2] \) makes the entire array sorted, so the answer is 2.
inputFormat
The input is read from standard input. The first line contains an integer \( T \), the number of test cases. Each test case consists of two lines:
- The first line contains an integer \( n \), the number of elements in the array.
- The second line contains \( n \) space-separated integers representing the array elements.
outputFormat
For each test case, output a single line containing the minimum length of the subarray that needs to be sorted.
## sample1
3
1 3 2
2
</p>