human
Check if sequence of removed middle elements from an array is sorted or not | Function to check if sequence of removed middle elements from an array is sorted or not.
Points toa the ends of the array.
Iterate l + 1 < r.
If the element at index L and R is greater than ( L + 1 ) - th and ( R - 1 ) - th elements.
If true , then decrement R by 1 and increment L by 1.
Otherwise , return false.
If an increasing sequence is formed , then return true.
Driver Code"
Solution in Python:
assistant
#Here is code to check if sequence of removed middle elements from an array is sorted or not and the other steps required.
 def isSortedArray ( arr , n ) :
	l = 0
	r = ( n - 1 )
	while ( ( l + 1 ) < r ) :
		if ( arr [ l ] >= max ( arr [ l + 1 ] , arr [ r - 1 ] ) and arr [ r ] >= max ( arr [ r - 1 ] , arr [ l + 1 ] ) ) :
			l += 1
			r -= 1
		else :
			return False
	return True
if __name__ == " _ _ main _ _ " :
	arr = [ 4 , 3 , 1 , 2 , 5 ]
	N = len ( arr )
	if ( isSortedArray ( arr , N ) ) :
		print ( " Yes " )
	else :
		print ( " No " )