title: Given A Sorted And Rotated Array Find If There Is A Pair With A Given Sum
signature: class Solution {
  
      public Boolean givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum(ArrayList<Integer> arr, Integer n, Integer x) {
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;
  }
question_info.extension: java
question_info.entry_fn_name: givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": false, "inputs": {"arr": [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], "n": 17, "x": 30}}, {"idx": 1, "outputs": false, "inputs": {"arr": [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], "n": 41, "x": 10}}, {"idx": 2, "outputs": true, "inputs": {"arr": [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], "n": 26, "x": 1}}, {"idx": 3, "outputs": false, "inputs": {"arr": [20, 68, 40, 19, 74, 69], "n": 4, "x": 88}}, {"idx": 4, "outputs": false, "inputs": {"arr": [-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], "n": 28, "x": 94}}, {"idx": 5, "outputs": false, "inputs": {"arr": [1, 1, 0], "n": 2, "x": 60}}, {"idx": 6, "outputs": false, "inputs": {"arr": [12, 22, 38, 76, 80, 86], "n": 4, "x": 3}}, {"idx": 7, "outputs": false, "inputs": {"arr": [-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], "n": 26, "x": 37}}, {"idx": 8, "outputs": false, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 17, "x": 20}}, {"idx": 9, "outputs": false, "inputs": {"arr": [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], "n": 21, "x": 27}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer x, Boolean expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n, x,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(20, 68, 40, 19, 74, 69)), 4, 88, false);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-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);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 1, 0)), 2, 60, false);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(12, 22, 38, 76, 80, 86)), 4, 3, false);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-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);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 17, 20, false);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer x, Boolean expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n, x),expected);
      }
      
      public boolean validateSolution(Boolean actual, Boolean expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__