human
Check if an array can be reduced to at most length K by removal of distinct elements | Function to check if it is possible to reduce the size of the array to K by removing the set of the distinct array elements.
Stores all distinct elements present in the array arr [ ].
Traverse the given array.
Insert array elements into the set.
Condition for reducing size of the array to at most K.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to check if an array can be reduced to at most length K by removal of distinct elements and the other steps required.
 def maxCount ( arr , N , K ) :
	st = set ( )
	for i in range ( N ) :
		st . add ( arr [ i ] )
	if ( N - len ( st ) <= K ) :
		print ( " Yes " )
	else :
		print ( " No " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 2 , 2 , 3 ]
	K = 3
	N = len ( arr )
	maxCount ( arr , N , K )