title: Ceiling In A Sorted Array 1
signature: class Solution {
  
      public int CeilingInASortedArray1(List<int> arr, int low, int high, int x) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int low, int high, int x, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, low, high, x); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{2, 6, 13, 16, 23, 24, 24, 27, 30, 32, 34, 34, 55, 56, 56, 63, 66, 81, 83, 96}, 13, 11, 18, 
                  13
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-28, -96, 48, 22, -12, 72, 48, -70, -96, -84, -62, 22, 18, -92, -74, 14, 28, 52, 64, 72, 16, -76, 46}, 11, 18, 21, 
                  11
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 1}, 1, 1, 1, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{51, 98, 25, 10, 43, 91, 33, 25, 85, 51, 94, 6, 35, 48, 11, 97, 67, 21, 50, 9, 11, 51, 86, 61, 22, 88, 89, 11}, 20, 20, 15, 
                  -1
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-94, -92, -88, -74, -52, -50, -48, -44, -40, -36, -32, -26, 20, 22, 30, 32, 46, 56, 56, 60, 62, 64, 80, 84, 86, 94, 96, 96}, 20, 15, 15, 
                  20
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, 15, 17, 22, 
                  -1
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{4, 5, 5, 13, 26, 40, 46, 51, 58, 60, 64, 66, 68, 69, 71, 74, 78, 81, 83, 88, 88, 90, 98, 99}, 12, 17, 14, 
                  12
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{92, 6, -54, 84, -10, 32, 50, 40, -38, 64, -64, -10, 70, -68, -6, -16, 68, 34, -66, -82, 84, 98, 50, 82, 78, 4, 34, -34, 78, 64, 32, 58, -94, 40, 50, 0, -92, -36, 10, -54, 58, -78, -88, 32, 6}, 23, 28, 28, 
                  23
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 24, 17, 22, 
                  -1
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{80, 67, 30, 35, 9}, 2, 3, 2, 
                  2
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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 );
    }
  }