title: Find Minimum Element In A Sorted And Rotated Array
signature: func findMinimumElementInASortedAndRotatedArray(arr []int, low int, high int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, low int, high int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, low, high),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{16, 22, 50, 64, 68, 79, 84, 88, 89}, 
  	4, 
  	6, 68)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{26, 66, 94, 28, 38, 31, 92, 66, 81, 8, 36, 64, 80, 32, 48, 71, 72, 54, 61, 60, 89}, 
  	19, 
  	17, 26)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-46, -26, -22, -14, 46, 62}, 
  	4, 
  	4, 46)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{0, 1, 1, 1}, 
  	2, 
  	2, 1)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{14, 81, 87}, 
  	1, 
  	1, 81)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{4}, 
  	0, 
  	0, 4)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	15, 
  	17, 1)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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 );
  }