title: Given A Sorted And Rotated Array Find If There Is A Pair With A Given Sum 1
signature: givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum1 :: [Integer] -> Integer -> Integer -> Integer
  givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum1 arr n x = 
test_code: import Text.Printf
  import Control.Exception (catch, SomeException)
  import Data.Typeable
  import qualified Data.List as List
  import qualified Data.Map as Map
  import qualified Data.Set as Set
  
  -- SOLUTION CODE
  -- ============================================
  
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  validateSolution :: Integer -> Integer -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: [Integer] -> Integer -> Integer -> Integer -> String
  driver arr n x expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME arr n x) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver ([24, 54]) (1) (1) (0) )
  
      printf "TEST-1...%s\n" (driver ([68, -30, -18, -6, 70, -40, 86, 98, -24, -48]) (8) (8) (0) )
  
      printf "TEST-2...%s\n" (driver ([0, 0, 0, 0, 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, 1, 1]) (33) (28) (0) )
  
      printf "TEST-3...%s\n" (driver ([84, 44, 40, 45, 2, 41, 52, 17, 50, 41, 5, 52, 48, 90, 13, 55, 34, 55, 94, 44, 41, 2]) (18) (16) (0) )
  
      printf "TEST-4...%s\n" (driver ([-92, -76, -74, -72, -68, -64, -58, -44, -44, -38, -26, -24, -20, -12, -8, -8, -4, 10, 10, 10, 20, 20, 26, 26, 28, 50, 52, 54, 60, 66, 72, 74, 78, 78, 78, 80, 86, 88]) (29) (30) (4) )
  
      printf "TEST-5...%s\n" (driver ([1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1]) (19) (10) (0) )
  
      printf "TEST-6...%s\n" (driver ([5, 5, 15, 19, 22, 24, 26, 27, 28, 32, 37, 39, 40, 43, 49, 52, 55, 56, 58, 58, 59, 62, 67, 68, 77, 79, 79, 80, 81, 87, 95, 95, 96, 98, 98]) (28) (34) (1) )
  
      printf "TEST-7...%s\n" (driver ([-98, 28, 54, 44, -98, -70, 48, -98, 56, 4, -18, 26, -8, -58, 30, 82, 4, -38, 42, 64, -28]) (17) (14) (0) )
  
      printf "TEST-8...%s\n" (driver ([0, 0, 0, 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]) (24) (24) (0) )
  
      printf "TEST-9...%s\n" (driver ([26, 72, 74, 86, 98, 86, 22, 6, 95, 36, 11, 82, 34, 3, 50, 36, 81, 94, 55, 30, 62, 53, 50, 95, 32, 83, 9, 16]) (19) (16) (0) )
  
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;
  }