title: Check Reversing Sub Array Make Array Sorted 1
signature: func checkReversingSubArrayMakeArraySorted1(arr []int, n int) bool {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual bool, expected bool) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, n int, expected bool) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{1, 2, 5, 4, 3}, 
  	5, false)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{1, 2, 4, 5, 3}, 
  	5, false)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{1, 1, 0, 0}, 
  	4, true)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-98, -92, -86, -58, -22, -12, 0, 26}, 
  	6, true)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{6, 10, 27, 30, 40, 47, 49, 55, 59, 60, 68, 82, 91}, 
  	8, true)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }