title: Recursive C Program Linearly Search Element Given Array
signature: int recursiveCProgramLinearlySearchElementGivenArray(vector<int> arr, int l, int r, int x) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int l, int r, int x, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, l, r, x), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({10, 74, 5}, 0, 2, 1, -1); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-90, 72, 36, 96, 42, 0, -66, 5}, 0, 7, 96, 3); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 5}, 0, 1, -1, -1); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({99, 70, 67, 5}, 0, 3, 3, -1); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-98, -98, -26, -26, -24, -18, -16, 80, 5}, 0, 8, 80, 7); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 1, 1, 1, 0, 1, 5}, 0, 6, 1, 0); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 5, 12, 12, 17, 17, 12, 95, 96, 98, 5}, 0, 0, 12, -1); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({50, -70, -30, -54, 6, -10, 70, 84, 5}, 0, 8, 27, -1); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 1, 5}, 0, 2, 14, -1); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({59, 21, 28, 3, 14, 5}, 0, 5, 28, 2); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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 );
  }