title: Search Insert And Delete In A Sorted Array
signature: class Solution {
  
      public Integer searchInsertAndDeleteInASortedArray(ArrayList<Integer> arr, Integer low, Integer high, Integer key) {
source_py: def search_insert_and_delete_in_a_sorted_array(arr, low, high, key):
      if (high < low):
          return (- 1)
      mid = ((low + high) / 2)
      if (key == arr[int(mid)]):
          return mid
      if (key > arr[int(mid)]):
          return search_insert_and_delete_in_a_sorted_array(arr, (mid + 1), high, key)
      return search_insert_and_delete_in_a_sorted_array(arr, low, (mid - 1), key)
source_cpp: int search_insert_and_delete_in_a_sorted_array(vector<int> arr, int low, int high, int key) {
    if ( high < low ) return - 1;
    int mid = ( low + high ) / 2;
    if ( key == arr [ mid ] ) return mid;
    if ( key > arr [ mid ] ) return search_insert_and_delete_in_a_sorted_array ( arr, ( mid + 1 ), high, key );
    return search_insert_and_delete_in_a_sorted_array ( arr, low, ( mid - 1 ), key );
  }
question_info.extension: java
question_info.entry_fn_name: searchInsertAndDeleteInASortedArray
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": -1, "inputs": {"arr": [2, 10, 73, 91, 98], "low": 2, "high": 4, "key": 4}}, {"idx": 1, "outputs": -1, "inputs": {"arr": [30, 24, 24, -8, 64, 50, 46, -76, 26, 8, -92, -78, 40, -86, 96, 14, 60, 38, 6, -72, -6, -20, 26, -26, 0, 2], "low": 20, "high": 13, "key": 21}}, {"idx": 2, "outputs": -1, "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": 30, "high": 27, "key": 29}}, {"idx": 3, "outputs": -1, "inputs": {"arr": [30, 79, 3, 76, 18], "low": 3, "high": 2, "key": 2}}, {"idx": 4, "outputs": -1, "inputs": {"arr": [-96, -90, -88, -84, -78, -78, -70, -68, -66, -66, -64, -64, -58, -56, -52, -42, -40, -38, -36, -30, -30, -28, -14, -8, 0, 14, 16, 22, 24, 26, 36, 40, 40, 48, 48, 50, 52, 54, 54, 58, 64, 74, 82, 88, 94], "low": 35, "high": 30, "key": 40}}, {"idx": 5, "outputs": -1, "inputs": {"arr": [1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1], "low": 25, "high": 26, "key": 30}}, {"idx": 6, "outputs": -1, "inputs": {"arr": [2, 8, 8, 14, 15, 16, 17, 17, 18, 18, 24, 25, 25, 26, 36, 37, 39, 39, 40, 44, 46, 47, 51, 54, 56, 57, 57, 61, 61, 67, 68, 69, 72, 76, 77, 81, 82, 82, 82, 85, 85, 87, 94, 94, 98, 99], "low": 33, "high": 40, "key": 26}}, {"idx": 7, "outputs": -1, "inputs": {"arr": [-4, 84, 20, -84, -6, -78, 20, 56, 40, 0, 98, 80, -94, 36, -6, -98, 50, 66, -12, -58, -34, 68, -80, -30, -82, -76, -38, -60, 92, 94, 48, -84, 20, -66, -32, -92, 16, -96, -68, 94, -46, 30, 32, -34, 96, -92, -96, -86, -22], "low": 34, "high": 27, "key": 34}}, {"idx": 8, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], "low": 19, "high": 13, "key": 19}}, {"idx": 9, "outputs": -1, "inputs": {"arr": [71, 70, 13, 18, 70, 62, 88, 27, 17, 44, 89, 28, 74, 41, 20, 91, 95, 79, 40, 43, 38, 20, 5], "low": 21, "high": 22, "key": 22}}]
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 key, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, low, high, key,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(2, 10, 73, 91, 98)), 2, 4, 4, -1);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(30, 24, 24, -8, 64, 50, 46, -76, 26, 8, -92, -78, 40, -86, 96, 14, 60, 38, 6, -72, -6, -20, 26, -26, 0, 2)), 20, 13, 21, -1);
          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)), 30, 27, 29, -1);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(30, 79, 3, 76, 18)), 3, 2, 2, -1);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-96, -90, -88, -84, -78, -78, -70, -68, -66, -66, -64, -64, -58, -56, -52, -42, -40, -38, -36, -30, -30, -28, -14, -8, 0, 14, 16, 22, 24, 26, 36, 40, 40, 48, 48, 50, 52, 54, 54, 58, 64, 74, 82, 88, 94)), 35, 30, 40, -1);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1)), 25, 26, 30, -1);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(2, 8, 8, 14, 15, 16, 17, 17, 18, 18, 24, 25, 25, 26, 36, 37, 39, 39, 40, 44, 46, 47, 51, 54, 56, 57, 57, 61, 61, 67, 68, 69, 72, 76, 77, 81, 82, 82, 82, 85, 85, 87, 94, 94, 98, 99)), 33, 40, 26, -1);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-4, 84, 20, -84, -6, -78, 20, 56, 40, 0, 98, 80, -94, 36, -6, -98, 50, 66, -12, -58, -34, 68, -80, -30, -82, -76, -38, -60, 92, 94, 48, -84, 20, -66, -32, -92, 16, -96, -68, 94, -46, 30, 32, -34, 96, -92, -96, -86, -22)), 34, 27, 34, -1);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 19, 13, 19, -1);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(71, 70, 13, 18, 70, 62, 88, 27, 17, 44, 89, 28, 74, 41, 20, 91, 95, 79, 40, 43, 38, 20, 5)), 21, 22, 22, -1);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer low, Integer high, Integer key, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, low, high, key),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__