human
Maximum element in a sorted and rotated array | Function to return the maximum element.
If there is only one element left.
Find mid.
Check if mid reaches 0 , it is greater than next element or not.
Check if mid itself is maximum element.
Decide whether we need to go to the left half or the right half.
Driver code"
Solution in Python:
assistant
#Here is code to maximum element in a sorted and rotated array and the other steps required.
 def findMax ( arr , low , high ) :
	if ( high == low ) :
		return arr [ low ]
	mid = low + ( high - low ) // 2
	if ( mid == 0 and arr [ mid ] > arr [ mid + 1 ] ) :
		return arr [ mid ]
	if ( mid < high and arr [ mid + 1 ] < arr [ mid ] and mid > 0 and arr [ mid ] > arr [ mid - 1 ] ) :
		return arr [ mid ]
	if ( arr [ low ] > arr [ mid ] ) :
		return findMax ( arr , low , mid - 1 )
	else :
		return findMax ( arr , mid + 1 , high )
arr = [ 6 , 5 , 4 , 3 , 2 , 1 ]
n = len ( arr )
print ( findMax ( arr , 0 , n - 1 ) )