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