title: Difference Between Highest And Least Frequencies In An Array
signature: fun differenceBetweenHighestAndLeastFrequenciesInAnArray(arr: ArrayList<Int>, n: Int): Int {
test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(arr: ArrayList<Int>, n: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(5, 15, 19, 22, 28, 29, 39, 46, 46, 49, 51, 55, 62, 69, 72, 72, 72, 74, 79, 92, 92, 93, 95, 96), 15, 1)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(-92, -92, -78, -74, -70, -66, -60, -54, -50, -48, -34, -32, -26, -24, -22, -14, -10, -10, -6, 2, 4, 6, 12, 18, 34, 42, 52, 56, 76, 92, 92), 30, 1)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 24, 0)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(1, 5, 13, 17, 21, 22, 25, 26, 29, 29, 31, 32, 35, 38, 40, 46, 48, 48, 49, 53, 54, 59, 61, 65, 65, 66, 73, 79, 81, 83, 92, 92, 93, 96, 97, 98), 29, 1)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-70, -34, -32, -30, -14, 80, 86, 90), 4, 0)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(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, 1, 1), 23, 0)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(9), 0, 0)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(10, 42, 70, 94), 2, 0)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(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), 24, 0)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(3, 4, 7, 8, 10, 15, 15, 17, 22, 26, 49, 55, 60, 64, 76, 79, 80, 84, 90, 92, 95, 96), 20, 1)
      println("TEST-9...${result}")
      
          
  }
  
  main()
source_py: def difference_between_highest_and_least_frequencies_in_an_array(arr, n):
      arr.sort()
      count = 0
      max_count = 0
      min_count = n
      for i in range(0, (n - 1)):
          if (arr[i] == arr[(i + 1)]):
              count += 1
              continue
          else:
              max_count = max(max_count, count)
              min_count = min(min_count, count)
              count = 0
      return (max_count - min_count)
source_cpp: int difference_between_highest_and_least_frequencies_in_an_array(vector<int> arr, int n) {
    sort(arr.begin(), arr.end());
    int count = 0, max_count = 0, min_count = n;
    for ( int i = 0;
    i < ( n - 1 );
    i ++ ) {
      if ( arr [ i ] == arr [ i + 1 ] ) {
        count += 1;
        continue;
      }
      else {
        max_count = max ( max_count, count );
        min_count = min ( min_count, count );
        count = 0;
      }
    }
    return ( max_count - min_count );
  }