title: Ceiling In A Sorted Array
signature: ceiling_in_a_sorted_array <- 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, 3L, 4L, 6L, 8L, 9L, 9L, 10L, 11L, 16L, 19L, 20L, 21L, 21L, 21L, 24L, 24L, 25L, 28L, 30L, 30L, 30L, 32L, 34L, 35L, 39L, 41L, 42L, 49L, 52L, 57L, 59L, 61L, 62L, 66L, 68L, 71L, 73L, 76L, 79L, 83L, 84L, 85L, 86L, 87L, 87L), 23L, 37L, 44L, 
          28L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(92L, 50L, -84L, 60L, 32L, -54L, 84L, -82L, -42L, -72L, -64L, -28L, -48L, 66L, 92L, -42L, 42L, -66L, 52L, -30L, 48L, 42L, 36L, -4L, 64L, 62L, -16L, 0L, 20L, 26L, 78L, 78L, 12L, -6L, -30L, -14L, 76L, 72L, 70L, -34L, 98L, 32L), 36L, 35L, 34L, 
          36L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L), 11L, 9L, 13L, 
          -1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(26L, 68L, 73L, 76L, 14L, 19L, 56L, 80L, 17L, 7L, 15L, 64L, 99L, 98L, 21L, 21L, 72L, 12L, 14L, 10L, 44L, 82L, 25L, 42L, 46L, 86L, 79L, 43L, 91L), 23L, 27L, 26L, 
          23L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-90L, -86L, -84L, -50L, -30L, -24L, -12L, -2L, 8L, 22L, 30L, 44L, 58L, 58L, 60L, 60L, 62L, 90L), 9L, 16L, 10L, 
          9L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L), 12L, 15L, 18L, 
          -1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(2L, 2L, 29L, 31L, 34L, 39L, 48L, 50L, 56L, 61L, 66L, 66L, 69L, 73L, 88L), 9L, 12L, 10L, 
          9L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-98L, 48L, -58L, 8L, 70L, 62L, 92L, 84L, -58L, -46L, -26L, -92L, 18L, -88L, 40L, -12L, 60L, 14L, 54L, -64L, 88L, 52L, -44L, 88L, -46L, -8L, 36L, -22L, 28L, -20L, -50L, 58L, -82L, -44L, -44L, 54L, -86L, 40L, 10L, 0L, -24L, -84L, -10L, 62L, 58L, 0L, -88L), 40L, 29L, 24L, 
          1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 1L, 1L), 5L, 5L, 5L, 
          -1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(56L, 30L, 33L, 5L, 67L, 35L, 22L, 54L, 36L, 55L, 94L, 89L, 40L, 65L, 29L, 76L, 17L, 14L, 14L, 49L, 40L, 44L, 35L, 69L, 63L, 2L, 81L, 78L, 19L, 67L, 12L, 14L, 68L, 30L, 82L, 85L, 12L, 2L, 94L, 33L, 85L, 75L, 97L, 31L, 69L, 31L, 85L, 26L), 46L, 47L, 47L, 
          46L
      )))
  
  }
  
  main()
source_py: def ceiling_in_a_sorted_array(arr, low, high, x):
      if (x <= arr[low]):
          return low
      i = low
      for i in range(high):
          if (arr[i] == x):
              return i
          if ((arr[i] < x) and (arr[(i + 1)] >= x)):
              return (i + 1)
      return (- 1)
source_cpp: int ceiling_in_a_sorted_array(vector<int> arr, int low, int high, int x) {
    int i;
    if ( x <= arr [ low ] ) return low;
    for ( i = low;
    i < high;
    i ++ ) {
      if ( arr [ i ] == x ) return i;
      if ( arr [ i ] < x && arr [ i + 1 ] >= x ) return i + 1;
    }
    return - 1;
  }