title: Difference Between Highest And Least Frequencies In An Array
signature: class Solution {
  
      public Integer differenceBetweenHighestAndLeastFrequenciesInAnArray(ArrayList<Integer> arr, Integer n) {
test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-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);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-70, -34, -32, -30, -14, 80, 86, 90)), 4, 0);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(9)), 0, 0);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(10, 42, 70, 94)), 2, 0);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(3, 4, 7, 8, 10, 15, 15, 17, 22, 26, 49, 55, 60, 64, 76, 79, 80, 84, 90, 92, 95, 96)), 20, 1);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
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 );
  }