title: Frequent Element Array
signature: class Solution {
  
      public int FrequentElementArray(List<int> arr, int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{1, 1, 3, 11, 11, 11, 18, 20, 26, 26, 27, 30, 33, 39, 39, 42, 42, 48, 51, 51, 51, 51, 60, 66, 66, 68, 68, 69, 71, 72, 73, 76, 76, 77, 77, 77, 78, 90, 96}, 25, 
                  51
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-74, -46, -38, -32, -22, -18, -14, -8, -4, 14, 30, 36, 42, 46, 48, 64, 66, 72, 80, 92, 94, 96, 96}, 18, 
                  -74
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 1}, 6, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{3, 21, 23, 31, 31, 32, 45, 49, 52, 55, 56, 58, 67, 70, 71, 80, 87, 93, 96, 97}, 15, 
                  31
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-98, -96, -84, -82, -72, -64, -62, -56, -52, -52, -48, -46, -42, -36, -32, -30, -30, -18, -16, -10, -2, 0, 6, 18, 22, 22, 40, 42, 50, 54, 64, 68, 68, 72, 80, 82, 84, 96}, 20, 
                  -52
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1}, 29, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{9, 12, 13, 28, 43, 46, 64, 66, 68, 89, 92}, 6, 
                  9
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-94, -88, -82, -80, -72, -60, -56, -52, -46, -42, -42, -40, -40, -32, -32, -26, -24, -22, -22, -12, -12, -8, 4, 6, 18, 18, 22, 22, 32, 36, 36, 38, 40, 46, 48, 50, 54, 68, 76, 78, 80, 86, 86, 90, 92, 92, 94, 96}, 41, 
                  -42
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 1, 1, 1}, 4, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{2, 4, 4, 5, 9, 16, 25, 29, 31, 32, 40, 41, 41, 43, 54, 61, 62, 63, 64, 65, 74, 74, 76, 80, 81, 81, 85, 86, 95, 96, 97, 97}, 16, 
                  4
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }