Length Unsorted Subarray
Submissions: 8045   Accuracy:

31.09%

  Difficulty: Easy   Marks: 2

Given an unsorted array A of size N. Find the subarray A[s..e] such that sorting this subarray makes the whole array sorted.

Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N, N is the size of array. The second line of each test case contains N elements.

Output:
Print the starting and ending index(0-based indexing) of subarray A[s..e]. If no such subarray exists, print 0 for starting index and 0 for ending index.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 107
1 ≤ C[i] ≤ 108

Example:
Input:
2
11
10 12 20 30 25 40 32 31 35 50 60
9
0 1 15 25 6 7 30 40 50

Output:
3 8
2 5

Explanation:
Testcase 1:
Subarray starting from index 3 and ending at index 8 is required subarray.

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.