title: Search Insert And Delete In A Sorted Array 1
signature: search_insert_and_delete_in_a_sorted_array_1 <- function(arr, n, key, capacity) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, key, capacity, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, key, capacity), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(69L), 0L, 0L, 0L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-34L, -38L, -72L, 90L, -84L, -40L, 6L, -52L, -12L, 80L, -4L, -58L), 6L, 6L, 9L, 
          7L
      )))
  
      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), 13L, 19L, 11L, 
          13L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(96L, 34L, 11L, 1L, 36L, 79L, 64L, 75L, 75L, 96L, 32L, 18L, 25L, 79L, 63L, 80L, 90L, 75L, 44L, 71L, 48L, 1L, 62L, 53L, 17L, 98L), 21L, 20L, 13L, 
          21L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -92L, -92L, -84L, -82L, -80L, -80L, -74L, -70L, -60L, -48L, -42L, -36L, -34L, -34L, -34L, -30L, -28L, -16L, -6L, -2L, -2L, 2L, 12L, 14L, 20L, 24L, 40L, 46L, 50L, 60L, 66L, 70L, 72L, 78L, 82L, 88L, 92L, 94L, 94L, 96L), 30L, 32L, 28L, 
          30L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L), 12L, 9L, 10L, 
          12L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(10L, 12L, 12L, 13L, 19L, 20L, 21L, 24L, 27L, 37L, 47L, 50L, 54L, 58L, 61L, 63L, 63L, 68L, 73L, 75L, 87L, 90L, 90L, 92L, 92L), 12L, 13L, 21L, 
          13L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-74L, 62L, 74L, 92L, -38L, -28L, -26L, 4L, 88L, -68L, -76L, -20L, -4L, 12L, 72L, 6L, 42L, 36L, 88L, -96L, -80L, 90L, 80L, -26L, -36L, -72L, -62L, 38L, -20L, 40L, -10L, -22L, -20L, 38L, 82L, -84L, 8L, 26L, 86L, -26L, 44L, -72L, -70L, -16L, -22L, 18L, -16L, 76L, -50L), 37L, 26L, 42L, 
          38L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(1L, 1L, 1L, 1L, 1L), 3L, 4L, 2L, 
          3L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(64L, 80L, 47L, 58L, 41L, 3L, 85L, 96L, 51L, 4L, 22L, 89L, 67L, 54L, 88L, 15L, 83L, 31L, 19L, 24L, 28L, 40L, 67L, 37L, 63L, 38L, 27L, 14L, 7L, 68L), 23L, 24L, 25L, 
          24L
      )))
  
  }
  
  main()
source_py: def search_insert_and_delete_in_a_sorted_array_1(arr, n, key, capacity):
      if (n >= capacity):
          return n
      i = (n - 1)
      while ((i >= 0) and (arr[i] > key)):
          arr[(i + 1)] = arr[i]
          i -= 1
      arr[(i + 1)] = key
      return (n + 1)
source_cpp: int search_insert_and_delete_in_a_sorted_array_1(vector<int> arr, int n, int key, int capacity) {
    if ( n >= capacity ) return n;
    int i;
    for ( i = n - 1;
    ( i >= 0 && arr [ i ] > key );
    i -- ) arr [ i + 1 ] = arr [ i ];
    arr [ i + 1 ] = key;
    return ( n + 1 );
  }