title: Frequent Element Array
signature: frequent_element_array <- 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(1L, 1L, 3L, 11L, 11L, 11L, 18L, 20L, 26L, 26L, 27L, 30L, 33L, 39L, 39L, 42L, 42L, 48L, 51L, 51L, 51L, 51L, 60L, 66L, 66L, 68L, 68L, 69L, 71L, 72L, 73L, 76L, 76L, 77L, 77L, 77L, 78L, 90L, 96L), 25L, 
          51L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-74L, -46L, -38L, -32L, -22L, -18L, -14L, -8L, -4L, 14L, 30L, 36L, 42L, 46L, 48L, 64L, 66L, 72L, 80L, 92L, 94L, 96L, 96L), 18L, 
          -74L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 1L), 6L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(3L, 21L, 23L, 31L, 31L, 32L, 45L, 49L, 52L, 55L, 56L, 58L, 67L, 70L, 71L, 80L, 87L, 93L, 96L, 97L), 15L, 
          31L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -96L, -84L, -82L, -72L, -64L, -62L, -56L, -52L, -52L, -48L, -46L, -42L, -36L, -32L, -30L, -30L, -18L, -16L, -10L, -2L, 0L, 6L, 18L, 22L, 22L, 40L, 42L, 50L, 54L, 64L, 68L, 68L, 72L, 80L, 82L, 84L, 96L), 20L, 
          -52L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 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, 1L, 1L, 1L, 1L, 1L), 29L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(9L, 12L, 13L, 28L, 43L, 46L, 64L, 66L, 68L, 89L, 92L), 6L, 
          9L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-94L, -88L, -82L, -80L, -72L, -60L, -56L, -52L, -46L, -42L, -42L, -40L, -40L, -32L, -32L, -26L, -24L, -22L, -22L, -12L, -12L, -8L, 4L, 6L, 18L, 18L, 22L, 22L, 32L, 36L, 36L, 38L, 40L, 46L, 48L, 50L, 54L, 68L, 76L, 78L, 80L, 86L, 86L, 90L, 92L, 92L, 94L, 96L), 41L, 
          -42L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), 4L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(2L, 4L, 4L, 5L, 9L, 16L, 25L, 29L, 31L, 32L, 40L, 41L, 41L, 43L, 54L, 61L, 62L, 63L, 64L, 65L, 74L, 74L, 76L, 80L, 81L, 81L, 85L, 86L, 95L, 96L, 97L, 97L), 16L, 
          4L
      )))
  
  }
  
  main()
source_py: def frequent_element_array(arr, n):
      arr.sort()
      max_count = 1
      res = arr[0]
      curr_count = 1
      for i in range(1, n):
          if (arr[i] == arr[(i - 1)]):
              curr_count += 1
          else:
              if (curr_count > max_count):
                  max_count = curr_count
                  res = arr[(i - 1)]
              curr_count = 1
      if (curr_count > max_count):
          max_count = curr_count
          res = arr[(n - 1)]
      return res
source_cpp: int frequent_element_array(vector<int> arr, int n) {
    sort(arr.begin(), arr.end());
    int max_count = 1, res = arr [ 0 ], curr_count = 1;
    for ( int i = 1;
    i < n;
    i ++ ) {
      if ( arr [ i ] == arr [ i - 1 ] ) curr_count ++;
      else {
        if ( curr_count > max_count ) {
          max_count = curr_count;
          res = arr [ i - 1 ];
        }
        curr_count = 1;
      }
    }
    if ( curr_count > max_count ) {
      max_count = curr_count;
      res = arr [ n - 1 ];
    }
    return res;
  }