title: Find Minimum Element In A Sorted And Rotated Array
signature: class Solution {
  
      public Integer findMinimumElementInASortedAndRotatedArray(ArrayList<Integer> arr, Integer low, Integer high) {
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 );
  }
question_info.extension: java
question_info.entry_fn_name: findMinimumElementInASortedAndRotatedArray
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 68, "inputs": {"arr": [16, 22, 50, 64, 68, 79, 84, 88, 89], "low": 4, "high": 6}}, {"idx": 1, "outputs": 88, "inputs": {"arr": [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], "low": 42, "high": 31}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [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], "low": 28, "high": 21}}, {"idx": 3, "outputs": 26, "inputs": {"arr": [26, 66, 94, 28, 38, 31, 92, 66, 81, 8, 36, 64, 80, 32, 48, 71, 72, 54, 61, 60, 89], "low": 19, "high": 17}}, {"idx": 4, "outputs": 46, "inputs": {"arr": [-46, -26, -22, -14, 46, 62], "low": 4, "high": 4}}, {"idx": 5, "outputs": 1, "inputs": {"arr": [0, 1, 1, 1], "low": 2, "high": 2}}, {"idx": 6, "outputs": 81, "inputs": {"arr": [14, 81, 87], "low": 1, "high": 1}}, {"idx": 7, "outputs": 4, "inputs": {"arr": [4], "low": 0, "high": 0}}, {"idx": 8, "outputs": 1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "low": 15, "high": 17}}, {"idx": 9, "outputs": 3, "inputs": {"arr": [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], "low": 42, "high": 31}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer low, Integer high, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, low, high,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(16, 22, 50, 64, 68, 79, 84, 88, 89)), 4, 6, 68);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(26, 66, 94, 28, 38, 31, 92, 66, 81, 8, 36, 64, 80, 32, 48, 71, 72, 54, 61, 60, 89)), 19, 17, 26);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-46, -26, -22, -14, 46, 62)), 4, 4, 46);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 1, 1, 1)), 2, 2, 1);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(14, 81, 87)), 1, 1, 81);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(4)), 0, 0, 4);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 15, 17, 1);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer low, Integer high, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, low, high),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__