title: Find Rotation Count Rotated Sorted Array 1
signature: find_rotation_count_rotated_sorted_array_1 <- function(arr, low, high) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, low, high, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, low, high), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(4L, 16L, 38L, 39L, 48L, 74L, 79L), 6L, 6L, 
          6L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-46L, 72L, 72L, -66L, 96L, 92L, 40L, 8L, 94L, -84L, 6L, -90L, 38L, -6L, 48L, -20L, -86L, -76L, 88L, -50L, -44L, -14L, 54L, -6L, -2L, 72L, 8L, -64L, -46L, 44L, -88L, 50L, 86L, 38L, 42L, -56L), 32L, 21L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(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), 16L, 29L, 
          29L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(48L, 74L, 59L, 57L, 95L, 11L, 25L, 61L, 46L, 54L, 34L, 84L, 7L, 97L, 62L, 57L, 99L, 93L, 76L, 5L, 76L, 93L, 35L, 84L, 37L, 60L, 65L, 16L, 30L, 73L, 42L, 61L, 74L, 77L, 48L, 62L, 84L, 93L, 64L, 57L, 68L, 46L, 28L, 77L), 24L, 26L, 
          24L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-72L, -68L, -66L, -66L, -62L, -62L, -52L, -48L, -42L, -42L, -42L, -38L, -30L, -22L, -20L, -20L, -16L, -16L, -14L, 0L, 2L, 2L, 2L, 4L, 12L, 20L, 22L, 26L, 32L, 34L, 46L, 46L, 64L, 64L, 64L, 66L, 68L, 68L, 68L, 74L, 80L, 84L, 84L, 88L, 88L, 90L, 96L, 98L), 29L, 43L, 
          31L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L), 0L, 0L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(7L, 11L, 20L, 21L, 22L, 27L, 30L, 30L, 34L, 35L, 36L, 37L, 38L, 60L, 61L, 63L, 63L, 69L, 70L, 75L, 80L, 84L, 88L, 97L), 23L, 22L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-2L, 70L, -40L), 2L, 1L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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), 30L, 17L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(71L, 71L, 27L, 10L, 97L, 43L, 55L, 71L, 6L, 6L, 77L, 48L, 77L, 2L, 83L, 51L, 61L, 19L, 2L, 51L, 26L, 70L, 20L, 23L, 54L, 15L, 6L, 92L, 35L, 75L, 8L, 57L, 50L, 49L, 88L, 21L, 36L), 24L, 22L, 
          0L
      )))
  
  }
  
  main()
source_py: def find_rotation_count_rotated_sorted_array_1(arr, low, high):
      if (high < low):
          return 0
      if (high == low):
          return low
      mid = (low + ((high - low) / 2))
      mid = int(mid)
      if ((mid < high) and (arr[(mid + 1)] < arr[mid])):
          return (mid + 1)
      if ((mid > low) and (arr[mid] < arr[(mid - 1)])):
          return mid
      if (arr[high] > arr[mid]):
          return find_rotation_count_rotated_sorted_array_1(arr, low, (mid - 1))
      return find_rotation_count_rotated_sorted_array_1(arr, (mid + 1), high)
source_cpp: int find_rotation_count_rotated_sorted_array_1(vector<int> arr, int low, int high) {
    if ( high < low ) return 0;
    if ( high == low ) return low;
    int mid = low + ( high - low ) / 2;
    if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 );
    if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid;
    if ( arr [ high ] > arr [ mid ] ) return find_rotation_count_rotated_sorted_array_1 ( arr, low, mid - 1 );
    return find_rotation_count_rotated_sorted_array_1 ( arr, mid + 1, high );
  }