title: Search Insert And Delete In A Sorted Array
signature: search_insert_and_delete_in_a_sorted_array <- function(arr, low, high, key) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, low, high, key, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, low, high, key), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 10L, 73L, 91L, 98L), 2L, 4L, 4L, 
          -1L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(30L, 24L, 24L, -8L, 64L, 50L, 46L, -76L, 26L, 8L, -92L, -78L, 40L, -86L, 96L, 14L, 60L, 38L, 6L, -72L, -6L, -20L, 26L, -26L, 0L, 2L), 20L, 13L, 21L, 
          -1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 30L, 27L, 29L, 
          -1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(30L, 79L, 3L, 76L, 18L), 3L, 2L, 2L, 
          -1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -90L, -88L, -84L, -78L, -78L, -70L, -68L, -66L, -66L, -64L, -64L, -58L, -56L, -52L, -42L, -40L, -38L, -36L, -30L, -30L, -28L, -14L, -8L, 0L, 14L, 16L, 22L, 24L, 26L, 36L, 40L, 40L, 48L, 48L, 50L, 52L, 54L, 54L, 58L, 64L, 74L, 82L, 88L, 94L), 35L, 30L, 40L, 
          -1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L), 25L, 26L, 30L, 
          -1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(2L, 8L, 8L, 14L, 15L, 16L, 17L, 17L, 18L, 18L, 24L, 25L, 25L, 26L, 36L, 37L, 39L, 39L, 40L, 44L, 46L, 47L, 51L, 54L, 56L, 57L, 57L, 61L, 61L, 67L, 68L, 69L, 72L, 76L, 77L, 81L, 82L, 82L, 82L, 85L, 85L, 87L, 94L, 94L, 98L, 99L), 33L, 40L, 26L, 
          -1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-4L, 84L, 20L, -84L, -6L, -78L, 20L, 56L, 40L, 0L, 98L, 80L, -94L, 36L, -6L, -98L, 50L, 66L, -12L, -58L, -34L, 68L, -80L, -30L, -82L, -76L, -38L, -60L, 92L, 94L, 48L, -84L, 20L, -66L, -32L, -92L, 16L, -96L, -68L, 94L, -46L, 30L, 32L, -34L, 96L, -92L, -96L, -86L, -22L), 34L, 27L, 34L, 
          -1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 19L, 13L, 19L, 
          -1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(71L, 70L, 13L, 18L, 70L, 62L, 88L, 27L, 17L, 44L, 89L, 28L, 74L, 41L, 20L, 91L, 95L, 79L, 40L, 43L, 38L, 20L, 5L), 21L, 22L, 22L, 
          -1L
      )))
  
  }
  
  main()
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 );
  }