title: Ceiling In A Sorted Array 1
signature: ceiling_in_a_sorted_array_1 <- function(arr, low, high, x) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, low, high, x, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, low, high, x), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 6L, 13L, 16L, 23L, 24L, 24L, 27L, 30L, 32L, 34L, 34L, 55L, 56L, 56L, 63L, 66L, 81L, 83L, 96L), 13L, 11L, 18L, 
          13L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-28L, -96L, 48L, 22L, -12L, 72L, 48L, -70L, -96L, -84L, -62L, 22L, 18L, -92L, -74L, 14L, 28L, 52L, 64L, 72L, 16L, -76L, 46L), 11L, 18L, 21L, 
          11L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 1L), 1L, 1L, 1L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(51L, 98L, 25L, 10L, 43L, 91L, 33L, 25L, 85L, 51L, 94L, 6L, 35L, 48L, 11L, 97L, 67L, 21L, 50L, 9L, 11L, 51L, 86L, 61L, 22L, 88L, 89L, 11L), 20L, 20L, 15L, 
          -1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-94L, -92L, -88L, -74L, -52L, -50L, -48L, -44L, -40L, -36L, -32L, -26L, 20L, 22L, 30L, 32L, 46L, 56L, 56L, 60L, 62L, 64L, 80L, 84L, 86L, 94L, 96L, 96L), 20L, 15L, 15L, 
          20L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L), 15L, 17L, 22L, 
          -1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(4L, 5L, 5L, 13L, 26L, 40L, 46L, 51L, 58L, 60L, 64L, 66L, 68L, 69L, 71L, 74L, 78L, 81L, 83L, 88L, 88L, 90L, 98L, 99L), 12L, 17L, 14L, 
          12L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(92L, 6L, -54L, 84L, -10L, 32L, 50L, 40L, -38L, 64L, -64L, -10L, 70L, -68L, -6L, -16L, 68L, 34L, -66L, -82L, 84L, 98L, 50L, 82L, 78L, 4L, 34L, -34L, 78L, 64L, 32L, 58L, -94L, 40L, 50L, 0L, -92L, -36L, 10L, -54L, 58L, -78L, -88L, 32L, 6L), 23L, 28L, 28L, 
          23L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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, 1L, 1L), 24L, 17L, 22L, 
          -1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(80L, 67L, 30L, 35L, 9L), 2L, 3L, 2L, 
          2L
      )))
  
  }
  
  main()
source_py: def ceiling_in_a_sorted_array_1(arr, low, high, x):
      if (x <= arr[low]):
          return low
      if (x > arr[high]):
          return (- 1)
      mid = ((low + high) / 2)
      if (arr[mid] == x):
          return mid
      elif (arr[mid] < x):
          if (((mid + 1) <= high) and (x <= arr[(mid + 1)])):
              return (mid + 1)
          else:
              return ceiling_in_a_sorted_array_1(arr, (mid + 1), high, x)
      elif (((mid - 1) >= low) and (x > arr[(mid - 1)])):
          return mid
      else:
          return ceiling_in_a_sorted_array_1(arr, low, (mid - 1), x)
source_cpp: int ceiling_in_a_sorted_array_1(vector<int> arr, int low, int high, int x) {
    int mid;
    if ( x <= arr [ low ] ) return low;
    if ( x > arr [ high ] ) return - 1;
    mid = ( low + high ) / 2;
    if ( arr [ mid ] == x ) return mid;
    else if ( arr [ mid ] < x ) {
      if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1;
      else return ceiling_in_a_sorted_array_1 ( arr, mid + 1, high, x );
    }
    else {
      if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid;
      else return ceiling_in_a_sorted_array_1 ( arr, low, mid - 1, x );
    }
  }