human
Find the maximum length of the prefix | Function to return the maximum length of the required prefix.
Array to store the frequency of each element of the array.
Iterating for all the elements.
Update the frequency of the current element i . e . v.
Sorted positive values from counts array.
If current prefix satisfies the given conditions.
Return the maximum length.
Driver code"
How can the above be solved in Python?
 What is a code to find the maximum length of the prefix and the other steps required?
assistant
#Here is code to find the maximum length of the prefix and the other steps required.
 def Maximum_Length ( a ) :
	counts = [ 0 ] * 11
	for index , v in enumerate ( a ) :
		counts [ v ] += 1
		k = sorted ( [ i for i in counts if i ] )
		if len ( k ) == 1 or ( k [ 0 ] == k [ - 2 ] and k [ - 1 ] - k [ - 2 ] == 1 ) or ( k [ 0 ] == 1 and k [ 1 ] == k [ - 1 ] ) :
			ans = index
	return ans + 1
if __name__ == " _ _ main _ _ " :
	a = [ 1 , 1 , 1 , 2 , 2 , 2 ]
	n = len ( a )
	print ( Maximum_Length ( a ) )