Shortest Un | Program to find the shortest subarray which is unsorted . ; boolean function to check array elements are in the increasing order or not ; boolean function to check array elements are in the decreasing order or not ; increasing and decreasing are two functions . function return true value then print 0 else 3 ; Driver program
using System ; class GFG { public static bool increasing ( int [ ] a , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) if ( a [ i ] >= a [ i + 1 ] ) return false ; return true ; } public static bool decreasing ( int [ ] arr , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] < arr [ i + 1 ] ) return false ; return true ; } public static int shortestUnsorted ( int [ ] a , int n ) { if ( increasing ( a , n ) == true || decreasing ( a , n ) == true ) return 0 ; else return 3 ; } public static void Main ( ) { int [ ] ar = new int [ ] { 7 , 9 , 10 , 8 , 11 } ; int n = ar . Length ; Console . WriteLine ( shortestUnsorted ( ar , n ) ) ; } }