title: Frequent Element Array
signature: function frequent_element_array(arr, n)
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;
  }