title: Difference Between Highest And Least Frequencies In An Array
signature: difference_between_highest_and_least_frequencies_in_an_array <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(5L, 15L, 19L, 22L, 28L, 29L, 39L, 46L, 46L, 49L, 51L, 55L, 62L, 69L, 72L, 72L, 72L, 74L, 79L, 92L, 92L, 93L, 95L, 96L), 15L, 
          1L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-92L, -92L, -78L, -74L, -70L, -66L, -60L, -54L, -50L, -48L, -34L, -32L, -26L, -24L, -22L, -14L, -10L, -10L, -6L, 2L, 4L, 6L, 12L, 18L, 34L, 42L, 52L, 56L, 76L, 92L, 92L), 30L, 
          1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 24L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(1L, 5L, 13L, 17L, 21L, 22L, 25L, 26L, 29L, 29L, 31L, 32L, 35L, 38L, 40L, 46L, 48L, 48L, 49L, 53L, 54L, 59L, 61L, 65L, 65L, 66L, 73L, 79L, 81L, 83L, 92L, 92L, 93L, 96L, 97L, 98L), 29L, 
          1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-70L, -34L, -32L, -30L, -14L, 80L, 86L, 90L), 4L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 23L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(9L), 0L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(10L, 42L, 70L, 94L), 2L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 24L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(3L, 4L, 7L, 8L, 10L, 15L, 15L, 17L, 22L, 26L, 49L, 55L, 60L, 64L, 76L, 79L, 80L, 84L, 90L, 92L, 95L, 96L), 20L, 
          1L
      )))
  
  }
  
  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 );
  }