Find counts of maximum and minimum frequent elements
int max_count = 0 , min_count = n ; foreach ( KeyValuePair < int , int > entry in mp ) { max_count = Math . Max ( max_count , entry . Value ) ; min_count = Math . Min ( min_count , entry . Value ) ; } return ( max_count - min_count ) ; }