title: Check Reversing Sub Array Make Array Sorted 1
signature: checkReversingSubArrayMakeArraySorted1 :: [Integer] -> Integer -> Bool
  checkReversingSubArrayMakeArraySorted1 arr n = 
test_code: import Text.Printf
  import Control.Exception (catch, SomeException)
  import Data.Typeable
  import qualified Data.List as List
  import qualified Data.Map as Map
  import qualified Data.Set as Set
  
  -- SOLUTION CODE
  -- ============================================
  
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  validateSolution :: Bool -> Bool -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: [Integer] -> Integer -> Bool -> String
  driver arr n expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME arr n) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver ([1, 2, 5, 4, 3]) (5) (False) )
  
      printf "TEST-1...%s\n" (driver ([1, 2, 4, 5, 3]) (5) (False) )
  
      printf "TEST-2...%s\n" (driver ([1, 1, 0, 0]) (4) (True) )
  
      printf "TEST-3...%s\n" (driver ([5, 99, 40, 33, 61, 4, 64, 92, 28, 27, 21, 35, 40, 79, 10, 20, 76, 87, 80, 15, 57, 39, 96, 98, 99, 72, 72, 50, 61, 39, 35, 70, 27]) (32) (True) )
  
      printf "TEST-4...%s\n" (driver ([-98, -92, -86, -58, -22, -12, 0, 26]) (6) (True) )
  
      printf "TEST-5...%s\n" (driver ([0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0]) (24) (True) )
  
      printf "TEST-6...%s\n" (driver ([6, 10, 27, 30, 40, 47, 49, 55, 59, 60, 68, 82, 91]) (8) (True) )
  
      printf "TEST-7...%s\n" (driver ([36, 56, -56, 94, 52, -82, 88, -62, 70, -94, 38, 10, -78, 66, -94, -72, 18, 96, -72, 88, -6, 48, 6, -88, 64, -96, -40, 8, 36, 36, -90, -68, -20, -76, 22, -92]) (30) (True) )
  
      printf "TEST-8...%s\n" (driver ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) (31) (True) )
  
      printf "TEST-9...%s\n" (driver ([2, 5, 42, 28, 47, 26, 88, 16, 30, 30, 36, 49, 21, 95, 99, 21, 41, 52, 57, 39, 69, 2, 42, 22, 55, 92, 64, 27, 95, 71, 19, 38, 40, 65, 7, 21, 29, 38, 13, 11, 41, 54, 38, 40, 35, 51, 88]) (46) (True) )
  
source_py: def check_reversing_sub_array_make_array_sorted_1(arr, n):
      if (n == 1):
          return True
      i = 1
      for i in range(1, n):
          if (arr[(i - 1)] < arr[i]):
              if (i == n):
                  return True
      j = i
      while (arr[j] < arr[(j - 1)]):
          if ((i > 1) and (arr[j] < arr[(i - 2)])):
              return False
          j += 1
      if (j == n):
          return True
      k = j
      if (arr[k] < arr[(i - 1)]):
          return False
      while ((k > 1) and (k < n)):
          if (arr[k] < arr[(k - 1)]):
              return False
          k += 1
      return True
source_cpp: bool check_reversing_sub_array_make_array_sorted_1(vector<int> arr, int n) {
    if ( n == 1 ) return true;
    int i;
    for ( i = 1;
    i < n && arr [ i - 1 ] < arr [ i ];
    i ++ );
    if ( i == n ) return true;
    int j = i;
    while ( arr [ j ] < arr [ j - 1 ] ) {
      if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false;
      j ++;
    }
    if ( j == n ) return true;
    int k = j;
    if ( arr [ k ] < arr [ i - 1 ] ) return false;
    while ( k > 1 && k < n ) {
      if ( arr [ k ] < arr [ k - 1 ] ) return false;
      k ++;
    }
    return true;
  }