title: Check Reversing Sub Array Make Array Sorted 1
signature: fun checkReversingSubArrayMakeArraySorted1(arr: ArrayList<Int>, n: Int): Boolean {
test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Boolean, expected:Boolean):Boolean{
    return actual.equals(expected)
  }
  fun driver(arr: ArrayList<Int>, n: Int, expected:Boolean):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(1, 2, 5, 4, 3), 5, false)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(1, 2, 4, 5, 3), 5, false)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(1, 1, 0, 0), 4, true)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(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)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-98, -92, -86, -58, -22, -12, 0, 26), 6, true)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(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)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(6, 10, 27, 30, 40, 47, 49, 55, 59, 60, 68, 82, 91), 8, true)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(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)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(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)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(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)
      println("TEST-9...${result}")
      
          
  }
  
  main()
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;
  }