Shortest un-ordered subarray
Submissions: 4162   Accuracy:

27.98%

  Difficulty: Basic   Marks: 1

Given an array of n distinct elements. Find the length of shortest unordered (neither increasing nor decreasing) sub array in given array.

Input:
The first line consists of an integer T i.e number of test cases. The first line of each test case consists of an integer n.The next line consists of n spaced numbers. 

Output:
Print the required output.

Constraints: 
1 <= T <= 100
1 <= n <= 100
1 <= a[i] <= 105

Example:
Input:

2
5
7 9 10 8 11
4
1 2 3 5

Output:
3
0

Explanation:
Testcase 1:
Shortest unsorted subarray is 9, 10, 8 which is of 3 elements.

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

Contributor: Saksham Ashtputre
Author: saksham0751


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.