title: Recursive C Program Linearly Search Element Given Array
signature: class Solution {
  
      public Integer recursiveCProgramLinearlySearchElementGivenArray(ArrayList<Integer> arr, Integer l, Integer r, Integer x) {
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 l, Integer r, Integer x, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, l, r, 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(10, 74, 5)), 0, 2, 1, -1);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-90, 72, 36, 96, 42, 0, -66, 5)), 0, 7, 96, 3);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 5)), 0, 1, -1, -1);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(99, 70, 67, 5)), 0, 3, 3, -1);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-98, -98, -26, -26, -24, -18, -16, 80, 5)), 0, 8, 80, 7);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 1, 1, 1, 0, 1, 5)), 0, 6, 1, 0);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 5, 12, 12, 17, 17, 12, 95, 96, 98, 5)), 0, 0, 12, -1);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(50, -70, -30, -54, 6, -10, 70, 84, 5)), 0, 8, 27, -1);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 1, 5)), 0, 2, 14, -1);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(59, 21, 28, 3, 14, 5)), 0, 5, 28, 2);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer l, Integer r, Integer x, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, l, r, x),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
source_py: def recursive_c_program_linearly_search_element_given_array(arr, l, r, x):
      if (r < l):
          return (- 1)
      if (arr[l] == x):
          return l
      if (arr[r] == x):
          return r
      return recursive_c_program_linearly_search_element_given_array(arr, (l + 1), (r - 1), x)
source_cpp: int recursive_c_program_linearly_search_element_given_array(vector<int> arr, int l, int r, int x) {
    if ( r < l ) return - 1;
    if ( arr [ l ] == x ) return l;
    if ( arr [ r ] == x ) return r;
    return recursive_c_program_linearly_search_element_given_array ( arr, l + 1, r - 1, x );
  }