title: Lower Insertion Point
signature: lower_insertion_point <- function(arr, n, x) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, x, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, x), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(1L, 2L, 5L, 5L, 16L, 16L, 20L, 26L, 32L, 35L, 39L, 39L, 41L, 44L, 48L, 48L, 51L, 59L, 59L, 62L, 66L, 66L, 70L, 74L, 75L, 78L, 80L, 86L, 86L, 96L), 17L, 29L, 
          8L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-76L, 80L, -6L, -2L, 50L, 72L, 84L, -56L, 70L, 8L, 48L, 6L, -24L, -50L, -72L), 14L, 9L, 
          14L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L), 8L, 4L, 
          8L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(74L, 65L, 84L, 71L), 2L, 3L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -92L, -90L, -86L, -84L, -76L, -76L, -62L, -58L, -54L, -50L, -50L, -44L, -42L, -38L, -34L, -14L, -8L, 6L, 12L, 24L, 38L, 40L, 50L, 62L, 84L, 86L, 92L), 19L, 19L, 
          19L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L), 12L, 17L, 
          12L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(6L, 10L, 14L, 14L, 16L, 19L, 23L, 23L, 25L, 26L, 29L, 34L, 42L, 42L, 43L, 45L, 47L, 49L, 50L, 51L, 51L, 56L, 59L, 65L, 69L, 72L, 75L, 78L, 79L, 80L, 82L, 82L, 82L, 84L, 85L, 91L, 98L), 31L, 24L, 
          8L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-90L, -2L, 22L, -2L, 58L, -2L, 96L, 38L, 36L, -66L, -98L, 22L, -80L, -32L, 22L, 0L, -34L, -16L, 82L, 76L, 12L, 84L, 66L, 8L, 32L, 18L, -98L, -10L), 22L, 16L, 
          2L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 1L, 1L, 1L, 1L), 3L, 5L, 
          3L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(85L, 59L, 22L, 52L, 93L, 14L, 42L, 71L, 69L, 15L, 52L, 78L, 35L, 61L, 92L, 90L, 70L, 48L, 47L, 72L, 74L, 46L, 22L, 74L, 83L, 32L, 14L, 24L, 18L, 27L, 18L, 68L, 29L, 31L), 19L, 33L, 
          0L
      )))
  
  }
  
  main()
source_py: def lower_insertion_point(arr, n, X):
      if (X < arr[0]):
          return 0
      elif (X > arr[(n - 1)]):
          return n
      lowerPnt = 0
      i = 1
      while ((i < n) and (arr[i] < X)):
          lowerPnt = i
          i = (i * 2)
      while ((lowerPnt < n) and (arr[lowerPnt] < X)):
          lowerPnt += 1
      return lowerPnt
source_cpp: int lower_insertion_point(vector<int> arr, int n, int X) {
    if ( X < arr [ 0 ] ) return 0;
    else if ( X > arr [ n - 1 ] ) return n;
    int lowerPnt = 0;
    int i = 1;
    while ( i < n && arr [ i ] < X ) {
      lowerPnt = i;
      i = i * 2;
    }
    while ( lowerPnt < n && arr [ lowerPnt ] < X ) lowerPnt ++;
    return lowerPnt;
  }