title: Given A Sorted And Rotated Array Find If There Is A Pair With A Given Sum 1
signature: function givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum1(arr, n, x) {
source_py: def given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum_1(arr, n, x):
      for i in range(n):
          if (arr[i] > arr[(i + 1)]):
              break
      l = ((i + 1) % n)
      r = i
      cnt = 0
      while (l != r):
          if ((arr[l] + arr[r]) == x):
              cnt += 1
              if (l == (((r - 1) + n) % n)):
                  return cnt
              l = ((l + 1) % n)
              r = (((r - 1) + n) % n)
          elif ((arr[l] + arr[r]) < x):
              l = ((l + 1) % n)
          else:
              r = (((n + r) - 1) % n)
      return cnt
source_cpp: int given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum_1(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;
    int cnt = 0;
    while ( l != r ) {
      if ( arr [ l ] + arr [ r ] == x ) {
        cnt ++;
        if ( l == ( r - 1 + n ) % n ) {
          return cnt;
        }
        l = ( l + 1 ) % n;
        r = ( r - 1 + n ) % n;
      }
      else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n;
      else r = ( n + r - 1 ) % n;
    }
    return cnt;
  }