title: Find A Fixed Point In A Given Array
signature: function find_a_fixed_point_in_a_given_array(arr, n)
source_py: def find_a_fixed_point_in_a_given_array(arr, n):
      for i in range(n):
          if (arr[i] is i):
              return i
      return (- 1)
source_cpp: int find_a_fixed_point_in_a_given_array(vector<int> arr, int n) {
    int i;
    for ( i = 0;
    i < n;
    i ++ ) {
      if ( arr [ i ] == i ) return i;
    }
    return - 1;
  }
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, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n) 
      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({8, 16, 21, 26, 27, 29, 34, 35, 35, 37, 38, 40, 48, 52, 58, 59, 60, 61, 63, 63, 65, 66, 69, 75, 79, 83, 86, 88, 91, 91, 96}, 23, -1)
      print(string.format("TEST-0...%s",result))
  
      result = driver({22, -70, 34, -44, 84, 54, 14, -88}, 7, -1)
      print(string.format("TEST-1...%s",result))
  
      result = driver({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, 1, 1}, 31, 0)
      print(string.format("TEST-2...%s",result))
  
      result = driver({59, 67, 70, 34, 18, 22, 52, 95, 11, 66, 60, 24, 7, 71, 52, 88, 32, 52, 85, 81, 32, 44, 25, 51, 47, 97, 81, 33, 88, 38, 36, 54, 80, 25, 70, 27, 75, 29, 94}, 37, -1)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-96, -96, -94, -88, -88, -82, -72, -72, -70, -70, -66, -64, -64, -62, -58, -54, -46, -44, -30, -26, -22, -8, -6, -2, 0, 26, 30, 30, 34, 42, 42, 48, 64, 76, 90, 96}, 34, -1)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1}, 15, 0)
      print(string.format("TEST-5...%s",result))
  
      result = driver({2, 2, 4, 7, 10, 15, 16, 16, 23, 24, 27, 39, 42, 58, 60, 64, 72, 74, 78, 78, 78, 80, 80, 84, 85, 86, 88, 88, 90, 92, 93, 94, 95, 96}, 22, -1)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-68, -48, 36, 22, -80, -48, -74, -14, 44, -46, -76, 18, -16, -36, -68, 0, -30, -56, 42, 92, 82, 64, -18, -6, -78, -86, 26, 86, 36, -66, -50, 18, -26, 48, 8}, 20, -1)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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, 1, 1, 1}, 23, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({3, 76, 99, 1, 1, 29, 9, 12, 57, 12, 74, 22, 83, 77, 39, 84, 50, 60, 36, 90, 88, 62, 79, 58, 58, 40, 44, 99, 84, 63, 23, 21, 16, 98, 68, 8, 46}, 35, -1)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": -1, "inputs": {"arr": [8, 16, 21, 26, 27, 29, 34, 35, 35, 37, 38, 40, 48, 52, 58, 59, 60, 61, 63, 63, 65, 66, 69, 75, 79, 83, 86, 88, 91, 91, 96], "n": 23}}, {"idx": 1, "outputs": -1, "inputs": {"arr": [22, -70, 34, -44, 84, 54, 14, -88], "n": 7}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [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, 1, 1], "n": 31}}, {"idx": 3, "outputs": -1, "inputs": {"arr": [59, 67, 70, 34, 18, 22, 52, 95, 11, 66, 60, 24, 7, 71, 52, 88, 32, 52, 85, 81, 32, 44, 25, 51, 47, 97, 81, 33, 88, 38, 36, 54, 80, 25, 70, 27, 75, 29, 94], "n": 37}}, {"idx": 4, "outputs": -1, "inputs": {"arr": [-96, -96, -94, -88, -88, -82, -72, -72, -70, -70, -66, -64, -64, -62, -58, -54, -46, -44, -30, -26, -22, -8, -6, -2, 0, 26, 30, 30, 34, 42, 42, 48, 64, 76, 90, 96], "n": 34}}, {"idx": 5, "outputs": 0, "inputs": {"arr": [0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1], "n": 15}}, {"idx": 6, "outputs": -1, "inputs": {"arr": [2, 2, 4, 7, 10, 15, 16, 16, 23, 24, 27, 39, 42, 58, 60, 64, 72, 74, 78, 78, 78, 80, 80, 84, 85, 86, 88, 88, 90, 92, 93, 94, 95, 96], "n": 22}}, {"idx": 7, "outputs": -1, "inputs": {"arr": [-68, -48, 36, 22, -80, -48, -74, -14, 44, -46, -76, 18, -16, -36, -68, 0, -30, -56, 42, 92, 82, 64, -18, -6, -78, -86, 26, 86, 36, -66, -50, 18, -26, 48, 8], "n": 20}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [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, 1, 1, 1], "n": 23}}, {"idx": 9, "outputs": -1, "inputs": {"arr": [3, 76, 99, 1, 1, 29, 9, 12, 57, 12, 74, 22, 83, 77, 39, 84, 50, 60, 36, 90, 88, 62, 79, 58, 58, 40, 44, 99, 84, 63, 23, 21, 16, 98, 68, 8, 46], "n": 35}}]
question_info.extension: lua
question_info.entry_fn_name: find_a_fixed_point_in_a_given_array
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__