title: Frequent Element Array 1
signature: function frequent_element_array_1(arr, n)
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({3, 5, 7, 9, 9, 10, 11, 15, 19, 19, 29, 31, 34, 34, 35, 37, 41, 43, 45, 47, 51, 51, 55, 57, 59, 61, 65, 67, 73, 76, 77, 77, 80, 83, 83, 84, 84, 92, 94}, 24, 9)
      print(string.format("TEST-0...%s",result))
  
      result = driver({14, -38, -84, 24, 82, -68, 60, 2, -22, 54, 90, 90, -38, -8, -72, 68, 50, 54, -32, -66, -10, -70, -28, 18, 58, -54, -30, 60, -24, -48, 22, 32, -18, 2, -64, -56, 70, -92, -38, -70, 22, -36, -64}, 28, -38)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 18, 1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({76, 18, 41, 46, 34, 41, 56, 76, 14, 82, 51, 87, 1, 92, 9, 2, 68, 82, 43, 98, 88, 62, 84, 25, 7, 87, 37, 7, 55, 98, 60, 99, 92, 56, 17, 82, 28, 43, 40, 1, 99, 79, 38, 75, 84, 61, 21, 11}, 37, 82)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-92, -86, -86, -84, -70, -68, -68, -66, -62, -52, -52, -50, -48, -38, -22, -14, -6, 4, 8, 10, 10, 16, 22, 36, 38, 40, 50, 50, 70, 78, 80, 86, 96, 96, 98}, 21, -86)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0}, 18, 1)
      print(string.format("TEST-5...%s",result))
  
      result = driver({3, 53, 56, 57, 66, 73, 76, 94, 97}, 8, 3)
      print(string.format("TEST-6...%s",result))
  
      result = driver({12, 60, -94, 92}, 3, 12)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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}, 21, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({95, 93, 82, 73, 61, 24, 73, 21, 47, 91, 48, 42, 76, 12, 89, 21, 3, 30, 5, 49, 26, 54, 16, 70, 50, 21, 58, 36, 16}, 25, 73)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
source_py: def frequent_element_array_1(arr, n):
      Hash = dict()
      for i in range(n):
          if (arr[i] in Hash.keys()):
              Hash[arr[i]] += 1
          else:
              Hash[arr[i]] = 1
      max_count = 0
      res = (- 1)
      for i in Hash:
          if (max_count < Hash[i]):
              res = i
              max_count = Hash[i]
      return res
source_cpp: int frequent_element_array_1(vector<int> arr, int n) {
    unordered_map < int, int > hash;
    for ( int i = 0;
    i < n;
    i ++ ) hash [ arr [ i ] ] ++;
    int max_count = 0, res = - 1;
    for ( auto i : hash ) {
      if ( max_count < i . second ) {
        res = i . first;
        max_count = i . second;
      }
    }
    return res;
  }