title: Find Minimum Element In A Sorted And Rotated Array
signature: function findMinimumElementInASortedAndRotatedArray($arr, $low, $high) {
test_code: <?php
  
  
  // SOLUTION CODE 
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function validateSolution($actual, $expected){
      return serialize($actual) == serialize($expected);
  }
  
  function driver($arr, $low, $high, $expected){
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME($arr, $low, $high), $expected)){
          return "PASSED";
        }
        return "FAILED";
      }
      catch (Exception $exception_obj) {
        return get_class($exception_obj);
      }
  }
  
  function main(){
      printf("TEST-0...%s\n",driver(
        array(16, 22, 50, 64, 68, 79, 84, 88, 89), 4, 6, 
        68));
      
      printf("TEST-1...%s\n",driver(
        array(88, -38, 46, 24, -52, -12, -90, 28, 18, 14, -72, 58, -98, 28, -84, 44, -42, -32, -22, -22, -82, -30, 90, 18, 62, 62, 92, 6, 60, 28, -90, 92, 82, 62, 98, -68, 48, -74, -8, 50, 62, 24, 30, -86, 98, -96, -98), 42, 31, 
        88));
      
      printf("TEST-2...%s\n",driver(
        array(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), 28, 21, 
        0));
      
      printf("TEST-3...%s\n",driver(
        array(26, 66, 94, 28, 38, 31, 92, 66, 81, 8, 36, 64, 80, 32, 48, 71, 72, 54, 61, 60, 89), 19, 17, 
        26));
      
      printf("TEST-4...%s\n",driver(
        array(-46, -26, -22, -14, 46, 62), 4, 4, 
        46));
      
      printf("TEST-5...%s\n",driver(
        array(0, 1, 1, 1), 2, 2, 
        1));
      
      printf("TEST-6...%s\n",driver(
        array(14, 81, 87), 1, 1, 
        81));
      
      printf("TEST-7...%s\n",driver(
        array(4), 0, 0, 
        4));
      
      printf("TEST-8...%s\n",driver(
        array(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 15, 17, 
        1));
      
      printf("TEST-9...%s\n",driver(
        array(3, 41, 40, 53, 82, 9, 90, 43, 90, 59, 37, 21, 92, 98, 36, 99, 35, 67, 24, 29, 40, 31, 46, 12, 29, 8, 93, 67, 44, 83, 71, 29, 22, 32, 33, 11, 44, 97, 84, 44, 8, 10, 31, 50, 22, 8), 42, 31, 
        3));
      
  }
  
  main();
  ?>
source_py: def find_minimum_element_in_a_sorted_and_rotated_array(arr, low, high):
      if (high < low):
          return arr[0]
      if (high == low):
          return arr[low]
      mid = int(((low + high) / 2))
      if ((mid < high) and (arr[(mid + 1)] < arr[mid])):
          return arr[(mid + 1)]
      if ((mid > low) and (arr[mid] < arr[(mid - 1)])):
          return arr[mid]
      if (arr[high] > arr[mid]):
          return find_minimum_element_in_a_sorted_and_rotated_array(arr, low, (mid - 1))
      return find_minimum_element_in_a_sorted_and_rotated_array(arr, (mid + 1), high)
source_cpp: int find_minimum_element_in_a_sorted_and_rotated_array(vector<int> arr, int low, int high) {
    if ( high < low ) return arr [ 0 ];
    if ( high == low ) return arr [ low ];
    int mid = low + ( high - low ) / 2;
    if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ];
    if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ];
    if ( arr [ high ] > arr [ mid ] ) return find_minimum_element_in_a_sorted_and_rotated_array ( arr, low, mid - 1 );
    return find_minimum_element_in_a_sorted_and_rotated_array ( arr, mid + 1, high );
  }