title: Frequent Element Array 1
signature: pub fn frequent_element_array_1(arr: Vec<i32>, n: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(arr: Vec<i32>, n: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-1...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-2...{}", driver(
        Vec::from([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), 18, 
        1
      ));
      
      println!("TEST-3...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-4...{}", driver(
        Vec::from([-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
      ));
      
      println!("TEST-5...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-6...{}", driver(
        Vec::from([3, 53, 56, 57, 66, 73, 76, 94, 97]), 8, 
        3
      ));
      
      println!("TEST-7...{}", driver(
        Vec::from([12, 60, -94, 92]), 3, 
        12
      ));
      
      println!("TEST-8...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-9...{}", driver(
        Vec::from([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
      ));
      
  }
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;
  }