human
Remove an occurrence of most frequent array element exactly K times | Function to print the most frequent array element exactly K times.
Stores frequency array element.
Count frequency of array element.
Maximum array element.
Traverse the Map.
Find the element with maximum frequency.
If the frequency is maximum , store that number in element.
Print element as it contains the element having highest frequency.
Decrease the frequency of the maximum array element.
Reduce the number of operations.
Given array.
Size of the array.
Given K"
Solution in Python:
assistant
#Here is code to remove an occurrence of most frequent array element exactly K times and the other steps required.
 def maxFreqElements ( arr , N , K ) :
	mp = { }
	for i in range ( N ) :
		if arr [ i ] in mp :
			mp [ arr [ i ] ] += 1
		else :
			mp [ arr [ i ] ] = 1
	while ( K > 0 ) :
		Max = 0
		for i in mp :
			if ( mp [ i ] > Max ) :
				Max = mp [ i ]
				element = i
		print ( element , end = " ▁ " )
		if element in mp :
			mp [ element ] -= 1
		else :
			mp [ element ] = - 1
		K -= 1
arr = [ 1 , 3 , 2 , 1 , 4 , 1 ]
N = len ( arr )
K = 2
maxFreqElements ( arr , N , K )