title: Check Reversing Sub Array Make Array Sorted 1
signature: check_reversing_sub_array_make_array_sorted_1 <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(1L, 2L, 5L, 4L, 3L), 5L, 
          FALSE
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(1L, 2L, 4L, 5L, 3L), 5L, 
          FALSE
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(1L, 1L, 0L, 0L), 4L, 
          TRUE
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(5L, 99L, 40L, 33L, 61L, 4L, 64L, 92L, 28L, 27L, 21L, 35L, 40L, 79L, 10L, 20L, 76L, 87L, 80L, 15L, 57L, 39L, 96L, 98L, 99L, 72L, 72L, 50L, 61L, 39L, 35L, 70L, 27L), 32L, 
          TRUE
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -92L, -86L, -58L, -22L, -12L, 0L, 26L), 6L, 
          TRUE
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L), 24L, 
          TRUE
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(6L, 10L, 27L, 30L, 40L, 47L, 49L, 55L, 59L, 60L, 68L, 82L, 91L), 8L, 
          TRUE
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(36L, 56L, -56L, 94L, 52L, -82L, 88L, -62L, 70L, -94L, 38L, 10L, -78L, 66L, -94L, -72L, 18L, 96L, -72L, 88L, -6L, 48L, 6L, -88L, 64L, -96L, -40L, 8L, 36L, 36L, -90L, -68L, -20L, -76L, 22L, -92L), 30L, 
          TRUE
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 31L, 
          TRUE
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(2L, 5L, 42L, 28L, 47L, 26L, 88L, 16L, 30L, 30L, 36L, 49L, 21L, 95L, 99L, 21L, 41L, 52L, 57L, 39L, 69L, 2L, 42L, 22L, 55L, 92L, 64L, 27L, 95L, 71L, 19L, 38L, 40L, 65L, 7L, 21L, 29L, 38L, 13L, 11L, 41L, 54L, 38L, 40L, 35L, 51L, 88L), 46L, 
          TRUE
      )))
  
  }
  
  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;
  }