human
What is a code to maximum frequencies in each M and the other steps required given the following:
Maximum frequencies in each M | Function to find the frequency of the most common element in each M length subarrays.
Stores frequency of array element.
Stores the maximum frequency.
Iterate for the first sub - array and store the maximum.
Print the maximum frequency for the first subarray.
Iterate over the range [ M , N ].
Subtract the A [ i - M ] and add the A [ i ] in the map.
Find the maximum frequency.
Print the maximum frequency for the current subarray.
Driver Code"
Solution in Python:
assistant
#Here is code to maximum frequencies in each M and the other steps required.
 def maxFrequencySubarrayUtil ( A , N , M ) :
	i = 0
	m = { }
	val = 0
	while ( i < M ) :
		if A [ i ] in m :
			m [ A [ i ] ] += 1
		else :
			m [ A [ i ] ] = 1
		val = max ( val , m [ A [ i ] ] )
		i += 1
	print ( val , end = " ▁ " )
	for i in range ( M , N , 1 ) :
		if A [ i - M ] in m :
			m [ A [ i - M ] ] -= 1
		else :
			m [ A [ i - M ] ] = 0
		if A [ i ] in m :
			m [ A [ i ] ] += 1
		val = 0
		for key , value in m . items ( ) :
			val = max ( val , value )
		print ( val , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	A = [ 1 , 1 , 2 , 2 , 3 , 5 ]
	N = len ( A )
	M = 4
	maxFrequencySubarrayUtil ( A , N , M )