human
Write me a code to find missing element in a sorted array of consecutive numbers and the other steps required given the following:
Find missing element in a sorted array of consecutive numbers | Function to return the missing element.
Check if middle element is consistent.
No inconsistency till middle elements When missing element is just after the middle element.
Move right.
Inconsistency found When missing element is just before the middle element.
Move left.
No missing element found.
Driver code"
Solution in Python:
assistant
#Here is code to find missing element in a sorted array of consecutive numbers and the other steps required.
 def findMissing ( arr , n ) :
	l , h = 0 , n - 1
	mid = 0
	while ( h > l ) :
		mid = l + ( h - l ) // 2
		if ( arr [ mid ] - mid == arr [ 0 ] ) :
			if ( arr [ mid + 1 ] - arr [ mid ] > 1 ) :
				return arr [ mid ] + 1
			else :
				l = mid + 1
		else :
			if ( arr [ mid ] - arr [ mid - 1 ] > 1 ) :
				return arr [ mid ] - 1
			else :
				h = mid - 1
	return - 1
arr = [ - 9 , - 8 , - 7 , - 5 , - 4 , - 3 , - 2 , - 1 , 0 ]
n = len ( arr )
print ( findMissing ( arr , n ) )