title: Check Reversing Sub Array Make Array Sorted 1
signature: def check_reversing_sub_array_make_array_sorted_1(arr, n):
test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(arr, n, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              arr, n),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver([1, 2, 5, 4, 3], 5, False)
      print(f"TEST-0...{result}")
  
      result = driver([1, 2, 4, 5, 3], 5, False)
      print(f"TEST-1...{result}")
  
      result = driver([1, 1, 0, 0], 4, True)
      print(f"TEST-2...{result}")
  
      result = 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)
      print(f"TEST-3...{result}")
  
      result = driver([-98, -92, -86, -58, -22, -12, 0, 26], 6, True)
      print(f"TEST-4...{result}")
  
      result = 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)
      print(f"TEST-5...{result}")
  
      result = driver([6, 10, 27, 30, 40, 47, 49, 55, 59, 60, 68, 82, 91], 8, True)
      print(f"TEST-6...{result}")
  
      result = 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)
      print(f"TEST-7...{result}")
  
      result = 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)
      print(f"TEST-8...{result}")
  
      result = 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)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
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;
  }