title: Given A Sorted And Rotated Array Find If There Is A Pair With A Given Sum 1
signature: pub fn given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum_1(arr: Vec<i32>, n: i32, x: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(arr: Vec<i32>, n: i32, x: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(arr, n, x), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        Vec::from([24, 54]), 1, 1, 
        0
      ));
      
      println!("TEST-1...{}", driver(
        Vec::from([68, -30, -18, -6, 70, -40, 86, 98, -24, -48]), 8, 8, 
        0
      ));
      
      println!("TEST-2...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-3...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-4...{}", driver(
        Vec::from([-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
      ));
      
      println!("TEST-5...{}", driver(
        Vec::from([1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1]), 19, 10, 
        0
      ));
      
      println!("TEST-6...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-7...{}", driver(
        Vec::from([-98, 28, 54, 44, -98, -70, 48, -98, 56, 4, -18, 26, -8, -58, 30, 82, 4, -38, 42, 64, -28]), 17, 14, 
        0
      ));
      
      println!("TEST-8...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-9...{}", driver(
        Vec::from([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;
  }