title: Ceiling In A Sorted Array
signature: function ceilingInASortedArray(arr: Array<number>, low: number, high: number, x: number): number {
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;
  }
question_info.test_list: [{"idx": 0, "outputs": 28, "inputs": {"arr": [2, 3, 4, 6, 8, 9, 9, 10, 11, 16, 19, 20, 21, 21, 21, 24, 24, 25, 28, 30, 30, 30, 32, 34, 35, 39, 41, 42, 49, 52, 57, 59, 61, 62, 66, 68, 71, 73, 76, 79, 83, 84, 85, 86, 87, 87], "low": 23, "high": 37, "x": 44}}, {"idx": 1, "outputs": 36, "inputs": {"arr": [92, 50, -84, 60, 32, -54, 84, -82, -42, -72, -64, -28, -48, 66, 92, -42, 42, -66, 52, -30, 48, 42, 36, -4, 64, 62, -16, 0, 20, 26, 78, 78, 12, -6, -30, -14, 76, 72, 70, -34, 98, 32], "low": 36, "high": 35, "x": 34}}, {"idx": 2, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], "low": 11, "high": 9, "x": 13}}, {"idx": 3, "outputs": 23, "inputs": {"arr": [26, 68, 73, 76, 14, 19, 56, 80, 17, 7, 15, 64, 99, 98, 21, 21, 72, 12, 14, 10, 44, 82, 25, 42, 46, 86, 79, 43, 91], "low": 23, "high": 27, "x": 26}}, {"idx": 4, "outputs": 9, "inputs": {"arr": [-90, -86, -84, -50, -30, -24, -12, -2, 8, 22, 30, 44, 58, 58, 60, 60, 62, 90], "low": 9, "high": 16, "x": 10}}, {"idx": 5, "outputs": -1, "inputs": {"arr": [0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1], "low": 12, "high": 15, "x": 18}}, {"idx": 6, "outputs": 9, "inputs": {"arr": [2, 2, 29, 31, 34, 39, 48, 50, 56, 61, 66, 66, 69, 73, 88], "low": 9, "high": 12, "x": 10}}, {"idx": 7, "outputs": 1, "inputs": {"arr": [-98, 48, -58, 8, 70, 62, 92, 84, -58, -46, -26, -92, 18, -88, 40, -12, 60, 14, 54, -64, 88, 52, -44, 88, -46, -8, 36, -22, 28, -20, -50, 58, -82, -44, -44, 54, -86, 40, 10, 0, -24, -84, -10, 62, 58, 0, -88], "low": 40, "high": 29, "x": 24}}, {"idx": 8, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 1, 1], "low": 5, "high": 5, "x": 5}}, {"idx": 9, "outputs": 46, "inputs": {"arr": [56, 30, 33, 5, 67, 35, 22, 54, 36, 55, 94, 89, 40, 65, 29, 76, 17, 14, 14, 49, 40, 44, 35, 69, 63, 2, 81, 78, 19, 67, 12, 14, 68, 30, 82, 85, 12, 2, 94, 33, 85, 75, 97, 31, 69, 31, 85, 26], "low": 46, "high": 47, "x": 47}}]
question_info.entry_cls_name: Solution
question_info.test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(arr: Array<number>, low: number, high: number, x: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, low, high, x),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver([2, 3, 4, 6, 8, 9, 9, 10, 11, 16, 19, 20, 21, 21, 21, 24, 24, 25, 28, 30, 30, 30, 32, 34, 35, 39, 41, 42, 49, 52, 57, 59, 61, 62, 66, 68, 71, 73, 76, 79, 83, 84, 85, 86, 87, 87], 23, 37, 44, 28);
    console.log(`TEST-0...${result}`);
  
    result = driver([92, 50, -84, 60, 32, -54, 84, -82, -42, -72, -64, -28, -48, 66, 92, -42, 42, -66, 52, -30, 48, 42, 36, -4, 64, 62, -16, 0, 20, 26, 78, 78, 12, -6, -30, -14, 76, 72, 70, -34, 98, 32], 36, 35, 34, 36);
    console.log(`TEST-1...${result}`);
  
    result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], 11, 9, 13, -1);
    console.log(`TEST-2...${result}`);
  
    result = driver([26, 68, 73, 76, 14, 19, 56, 80, 17, 7, 15, 64, 99, 98, 21, 21, 72, 12, 14, 10, 44, 82, 25, 42, 46, 86, 79, 43, 91], 23, 27, 26, 23);
    console.log(`TEST-3...${result}`);
  
    result = driver([-90, -86, -84, -50, -30, -24, -12, -2, 8, 22, 30, 44, 58, 58, 60, 60, 62, 90], 9, 16, 10, 9);
    console.log(`TEST-4...${result}`);
  
    result = driver([0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1], 12, 15, 18, -1);
    console.log(`TEST-5...${result}`);
  
    result = driver([2, 2, 29, 31, 34, 39, 48, 50, 56, 61, 66, 66, 69, 73, 88], 9, 12, 10, 9);
    console.log(`TEST-6...${result}`);
  
    result = driver([-98, 48, -58, 8, 70, 62, 92, 84, -58, -46, -26, -92, 18, -88, 40, -12, 60, 14, 54, -64, 88, 52, -44, 88, -46, -8, 36, -22, 28, -20, -50, 58, -82, -44, -44, 54, -86, 40, 10, 0, -24, -84, -10, 62, 58, 0, -88], 40, 29, 24, 1);
    console.log(`TEST-7...${result}`);
  
    result = driver([0, 0, 0, 0, 1, 1], 5, 5, 5, -1);
    console.log(`TEST-8...${result}`);
  
    result = driver([56, 30, 33, 5, 67, 35, 22, 54, 36, 55, 94, 89, 40, 65, 29, 76, 17, 14, 14, 49, 40, 44, 35, 69, 63, 2, 81, 78, 19, 67, 12, 14, 68, 30, 82, 85, 12, 2, 94, 33, 85, 75, 97, 31, 69, 31, 85, 26], 46, 47, 47, 46);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: ceilingInASortedArray
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js