title: Given A Sorted And Rotated Array Find If There Is A Pair With A Given Sum
signature: given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum <- 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(3L, 8L, 10L, 15L, 18L, 19L, 20L, 20L, 21L, 22L, 26L, 30L, 32L, 34L, 43L, 45L, 50L, 50L, 51L, 52L, 53L, 56L, 57L, 58L, 62L, 63L, 65L, 82L, 86L, 91L, 91L, 92L, 92L, 93L, 97L), 17L, 30L, 
          FALSE
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(30L, -34L, 86L, -30L, -26L, 2L, 90L, 8L, 26L, -8L, -8L, 0L, -86L, 68L, 22L, 72L, -76L, 48L, -24L, 90L, -22L, -58L, -54L, 90L, -12L, -12L, 88L, 72L, -58L, 68L, 84L, 22L, 60L, 66L, -52L, -38L, -90L, 62L, 30L, -26L, 88L, -36L, 92L, 32L, -32L, -42L, -90L, -40L, -10L), 41L, 10L, 
          FALSE
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(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), 26L, 1L, 
          TRUE
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(20L, 68L, 40L, 19L, 74L, 69L), 4L, 88L, 
          FALSE
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -94L, -94L, -94L, -90L, -88L, -88L, -78L, -74L, -70L, -68L, -66L, -64L, -62L, -54L, -50L, -40L, -40L, -40L, -40L, -28L, -22L, -22L, -18L, -14L, -12L, 0L, 6L, 6L, 8L, 12L, 20L, 22L, 26L, 28L, 36L, 42L, 44L, 48L, 52L, 56L, 60L, 68L, 84L), 28L, 94L, 
          FALSE
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 0L), 2L, 60L, 
          FALSE
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(12L, 22L, 38L, 76L, 80L, 86L), 4L, 3L, 
          FALSE
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-36L, -10L, -26L, 34L, -50L, 66L, -2L, -14L, -62L, 60L, -48L, 94L, -70L, 6L, -60L, -90L, 28L, -4L, -20L, -52L, 40L, -76L, -92L, -14L, 54L, 4L, -58L, 38L, -74L, -96L, -88L, 86L, -54L, 98L, 48L, 68L, 78L, -28L, -80L, -46L), 26L, 37L, 
          FALSE
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 17L, 20L, 
          FALSE
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(69L, 99L, 25L, 52L, 41L, 51L, 7L, 33L, 42L, 91L, 85L, 57L, 91L, 89L, 86L, 11L, 70L, 67L, 30L, 92L, 81L, 23L, 51L, 98L, 85L, 5L, 50L, 44L), 21L, 27L, 
          FALSE
      )))
  
  }
  
  main()
source_py: def given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum(arr, n, x):
      for i in range(0, (n - 1)):
          if (arr[i] > arr[(i + 1)]):
              break
      l = ((i + 1) % n)
      r = i
      while (l != r):
          if ((arr[l] + arr[r]) == x):
              return True
          if ((arr[l] + arr[r]) < x):
              l = ((l + 1) % n)
          else:
              r = (((n + r) - 1) % n)
      return False
source_cpp: bool given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum(vector<int> arr, int n, int x) {
    int i;
    for ( i = 0;
    i < n - 1;
    i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break;
    int l = ( i + 1 ) % n;
    int r = i;
    while ( l != r ) {
      if ( arr [ l ] + arr [ r ] == x ) return true;
      if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n;
      else r = ( n + r - 1 ) % n;
    }
    return false;
  }