human
Minimum deletions required such that any number X will occur exactly X times | Function to return the minimum deletions required.
To store the frequency of the array elements.
Store frequency of each element.
To store the minimum deletions required.
Value.
It 's frequency.
If number less than or equal to it 's frequency.
Delete extra occurrences.
Delete every occurrence of x.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to minimum deletions required such that any number X will occur exactly X times and the other steps required.
 def MinDeletion ( a , n ) :
	map = dict . fromkeys ( a , 0 ) ;
	for i in range ( n ) :
		map [ a [ i ] ] += 1 ;
	ans = 0 ;
	for key , value in map . items ( ) :
		x = key ;
		frequency = value ;
		if ( x <= frequency ) :
			ans += ( frequency - x ) ;
		else :
			ans += frequency ;
	return ans ;
if __name__ == " _ _ main _ _ " :
	a = [ 2 , 3 , 2 , 3 , 4 , 4 , 4 , 4 , 5 ] ;
	n = len ( a ) ;
	print ( MinDeletion ( a , n ) ) ;