title: Given A Sorted And Rotated Array Find If There Is A Pair With A Given Sum
signature: fun givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum(arr: ArrayList<Int>, n: Int, x: Int): Boolean {
test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Boolean, expected:Boolean):Boolean{
    return actual.equals(expected)
  }
  fun driver(arr: ArrayList<Int>, n: Int, x: Int, expected:Boolean):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(3, 8, 10, 15, 18, 19, 20, 20, 21, 22, 26, 30, 32, 34, 43, 45, 50, 50, 51, 52, 53, 56, 57, 58, 62, 63, 65, 82, 86, 91, 91, 92, 92, 93, 97), 17, 30, false)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(30, -34, 86, -30, -26, 2, 90, 8, 26, -8, -8, 0, -86, 68, 22, 72, -76, 48, -24, 90, -22, -58, -54, 90, -12, -12, 88, 72, -58, 68, 84, 22, 60, 66, -52, -38, -90, 62, 30, -26, 88, -36, 92, 32, -32, -42, -90, -40, -10), 41, 10, false)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 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, 1), 26, 1, true)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(20, 68, 40, 19, 74, 69), 4, 88, false)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-98, -94, -94, -94, -90, -88, -88, -78, -74, -70, -68, -66, -64, -62, -54, -50, -40, -40, -40, -40, -28, -22, -22, -18, -14, -12, 0, 6, 6, 8, 12, 20, 22, 26, 28, 36, 42, 44, 48, 52, 56, 60, 68, 84), 28, 94, false)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(1, 1, 0), 2, 60, false)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(12, 22, 38, 76, 80, 86), 4, 3, false)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(-36, -10, -26, 34, -50, 66, -2, -14, -62, 60, -48, 94, -70, 6, -60, -90, 28, -4, -20, -52, 40, -76, -92, -14, 54, 4, -58, 38, -74, -96, -88, 86, -54, 98, 48, 68, 78, -28, -80, -46), 26, 37, false)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1), 17, 20, false)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(69, 99, 25, 52, 41, 51, 7, 33, 42, 91, 85, 57, 91, 89, 86, 11, 70, 67, 30, 92, 81, 23, 51, 98, 85, 5, 50, 44), 21, 27, false)
      println("TEST-9...${result}")
      
          
  }
  
  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;
  }