human
Write me a code to minimum operations required to make all the array elements equal and the other steps required given the following:
Minimum operations required to make all the array elements equal | Function to return the minimum number of given operation required to make all the array elements equal.
Check if all the elements from kth index to last are equal.
Finding the 1 st element which is not equal to the kth element.
Driver code"
Solution in Python:
assistant
#Here is code to minimum operations required to make all the array elements equal and the other steps required.
 def minOperation ( n , k , a ) :
	for i in range ( k , n ) :
		if ( a [ i ] != a [ k - 1 ] ) :
			return - 1
	for i in range ( k - 2 , - 1 , - 1 ) :
		if ( a [ i ] != a [ k - 1 ] ) :
			return i + 1
n = 5
k = 3
a = [ 2 , 1 , 1 , 1 , 1 ]
print ( minOperation ( n , k , a ) )