#C10643. Find Unsorted Subarray Challenge
Find Unsorted Subarray Challenge
Find Unsorted Subarray Challenge
You are given an integer array. Your task is to find the shortest continuous subarray such that if you sort this subarray, the whole array becomes sorted in non-decreasing order.
Formally, for an array \(A[0 \ldots N-1]\), find indices \(L\) and \(R\) such that sorting the subarray \(A[L\ldots R]\) results in the entire array being sorted. If the given array is already sorted, output \(-1\) for both indices.
The indices should be based on 0-indexing.
Note: Use standard input (stdin) for reading and standard output (stdout) for printing your answer.
inputFormat
The first line of input contains an integer \(N\) representing the number of elements in the array.
The second line contains \(N\) space-separated integers representing the array elements.
outputFormat
Output two integers separated by a space representing the start and end indices of the shortest subarray which, if sorted, makes the whole array sorted. If the array is already sorted, output "-1 -1".
## sample4
1 2 3 4
-1 -1
</p>