human
Reduce array to a single element by repeatedly replacing adjacent unequal pairs with their maximum | Function to prthe index from where the operation can be started.
Initialize B.
Initialize save.
Make B equals to arr.
Sort the array B.
Traverse from N - 1 to 1.
If B [ i ] & B [ i - 1 ] are unequal.
If all elements are same.
If arr [ 1 ] is maximum element.
If arr [ N - 1 ] is maximum element.
Find the maximum element.
Driver Code.
Given array arr.
Length of array.
Function Call"
Solution in Python:
assistant
#Here is code to reduce array to a single element by repeatedly replacing adjacent unequal pairs with their maximum and the other steps required.
 def printIndex ( arr , N ) :
	B = [ 0 ] * ( N )
	save = - 1
	for i in range ( N ) :
		B [ i ] = arr [ i ]
	B = sorted ( B )
	for i in range ( N - 1 , 1 , - 1 ) :
		if ( B [ i ] != B [ i - 1 ] ) :
			save = B [ i ]
			break
	if ( save == - 1 ) :
		print ( - 1 + " " )
		return
	if ( save == arr [ 0 ] and save != arr [ 1 ] ) :
		print ( 1 )
	elif ( save == arr [ N - 1 ] and save != arr [ N - 2 ] ) :
		print ( N )
	for i in range ( 1 , N - 1 ) :
		if ( save == arr [ i ] and ( save != arr [ i - 1 ] or save != arr [ i + 1 ] ) ) :
			print ( i + 1 )
			break
if __name__ == ' _ _ main _ _ ' :
	arr = [ 5 , 3 , 4 , 4 , 5 ]
	N = len ( arr )
	printIndex ( arr , N )