BETA
Shortest un-ordered subarray
Submissions: 3531   Accuracy:

29.55%

  Difficulty: Basic
     

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


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