title: Frequent Element Array
signature: def frequentElementArray(arr: List[Int], n: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(arr: List[Int], n: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-1...${driver(
        List(-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    
      )}")   
  
  
      println(s"TEST-2...${driver(
        List(0, 0, 0, 0, 0, 0, 1), 6, 
        0    
      )}")   
  
  
      println(s"TEST-3...${driver(
        List(3, 21, 23, 31, 31, 32, 45, 49, 52, 55, 56, 58, 67, 70, 71, 80, 87, 93, 96, 97), 15, 
        31    
      )}")   
  
  
      println(s"TEST-4...${driver(
        List(-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    
      )}")   
  
  
      println(s"TEST-5...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-6...${driver(
        List(9, 12, 13, 28, 43, 46, 64, 66, 68, 89, 92), 6, 
        9    
      )}")   
  
  
      println(s"TEST-7...${driver(
        List(-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    
      )}")   
  
  
      println(s"TEST-8...${driver(
        List(0, 0, 0, 0, 0, 0, 1, 1, 1), 4, 
        0    
      )}")   
  
  
      println(s"TEST-9...${driver(
        List(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    
      )}")   
  
  }
  
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;
  }