Find counts of maximum and minimum frequent elements
int max_count = 0 , min_count = n ; for ( auto x : hm ) { max_count = max ( max_count , x . second ) ; min_count = min ( min_count , x . second ) ; } return ( max_count - min_count ) ; }