title: Recursive C Program Linearly Search Element Given Array
signature: function recursive_c_program_linearly_search_element_given_array(arr, l, r, x)
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 );
  }
question_info.entry_fn_name: recursive_c_program_linearly_search_element_given_array
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, l, r, x, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, l, r, x) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({10, 74, 5}, 0, 2, 1, -1)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-90, 72, 36, 96, 42, 0, -66, 5}, 0, 7, 96, 3)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 5}, 0, 1, -1, -1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({99, 70, 67, 5}, 0, 3, 3, -1)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -98, -26, -26, -24, -18, -16, 80, 5}, 0, 8, 80, 7)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 1, 1, 1, 0, 1, 5}, 0, 6, 1, 0)
      print(string.format("TEST-5...%s",result))
  
      result = driver({1, 5, 12, 12, 17, 17, 12, 95, 96, 98, 5}, 0, 0, 12, -1)
      print(string.format("TEST-6...%s",result))
  
      result = driver({50, -70, -30, -54, 6, -10, 70, 84, 5}, 0, 8, 27, -1)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 1, 5}, 0, 2, 14, -1)
      print(string.format("TEST-8...%s",result))
  
      result = driver({59, 21, 28, 3, 14, 5}, 0, 5, 28, 2)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": -1, "inputs": {"arr": [10, 74, 5], "l": 0, "r": 2, "x": 1}}, {"idx": 1, "outputs": 3, "inputs": {"arr": [-90, 72, 36, 96, 42, 0, -66, 5], "l": 0, "r": 7, "x": 96}}, {"idx": 2, "outputs": -1, "inputs": {"arr": [0, 5], "l": 0, "r": 1, "x": -1}}, {"idx": 3, "outputs": -1, "inputs": {"arr": [99, 70, 67, 5], "l": 0, "r": 3, "x": 3}}, {"idx": 4, "outputs": 7, "inputs": {"arr": [-98, -98, -26, -26, -24, -18, -16, 80, 5], "l": 0, "r": 8, "x": 80}}, {"idx": 5, "outputs": 0, "inputs": {"arr": [1, 1, 1, 1, 0, 1, 5], "l": 0, "r": 6, "x": 1}}, {"idx": 6, "outputs": -1, "inputs": {"arr": [1, 5, 12, 12, 17, 17, 12, 95, 96, 98, 5], "l": 0, "r": 0, "x": 12}}, {"idx": 7, "outputs": -1, "inputs": {"arr": [50, -70, -30, -54, 6, -10, 70, 84, 5], "l": 0, "r": 8, "x": 27}}, {"idx": 8, "outputs": -1, "inputs": {"arr": [0, 1, 5], "l": 0, "r": 2, "x": 14}}, {"idx": 9, "outputs": 2, "inputs": {"arr": [59, 21, 28, 3, 14, 5], "l": 0, "r": 5, "x": 28}}]