title: Frequent Element Array 1
signature: frequent_element_array_1 <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(3L, 5L, 7L, 9L, 9L, 10L, 11L, 15L, 19L, 19L, 29L, 31L, 34L, 34L, 35L, 37L, 41L, 43L, 45L, 47L, 51L, 51L, 55L, 57L, 59L, 61L, 65L, 67L, 73L, 76L, 77L, 77L, 80L, 83L, 83L, 84L, 84L, 92L, 94L), 24L, 
          9L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(14L, -38L, -84L, 24L, 82L, -68L, 60L, 2L, -22L, 54L, 90L, 90L, -38L, -8L, -72L, 68L, 50L, 54L, -32L, -66L, -10L, -70L, -28L, 18L, 58L, -54L, -30L, 60L, -24L, -48L, 22L, 32L, -18L, 2L, -64L, -56L, 70L, -92L, -38L, -70L, 22L, -36L, -64L), 28L, 
          -38L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 18L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(76L, 18L, 41L, 46L, 34L, 41L, 56L, 76L, 14L, 82L, 51L, 87L, 1L, 92L, 9L, 2L, 68L, 82L, 43L, 98L, 88L, 62L, 84L, 25L, 7L, 87L, 37L, 7L, 55L, 98L, 60L, 99L, 92L, 56L, 17L, 82L, 28L, 43L, 40L, 1L, 99L, 79L, 38L, 75L, 84L, 61L, 21L, 11L), 37L, 
          82L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-92L, -86L, -86L, -84L, -70L, -68L, -68L, -66L, -62L, -52L, -52L, -50L, -48L, -38L, -22L, -14L, -6L, 4L, 8L, 10L, 10L, 16L, 22L, 36L, 38L, 40L, 50L, 50L, 70L, 78L, 80L, 86L, 96L, 96L, 98L), 21L, 
          -86L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L), 18L, 
          1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 53L, 56L, 57L, 66L, 73L, 76L, 94L, 97L), 8L, 
          3L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(12L, 60L, -94L, 92L), 3L, 
          12L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 21L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(95L, 93L, 82L, 73L, 61L, 24L, 73L, 21L, 47L, 91L, 48L, 42L, 76L, 12L, 89L, 21L, 3L, 30L, 5L, 49L, 26L, 54L, 16L, 70L, 50L, 21L, 58L, 36L, 16L), 25L, 
          73L
      )))
  
  }
  
  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;
  }