human
Minimum elements to be removed from the ends to make the array sorted | Function to return the minimum number of elements to be removed from the ends of the array to make it sorted.
To store the final answer.
Two pointer loop.
While the array is increasing increment j.
Updating the ans.
Updating the left pointer.
Returning the final answer.
Driver code"
How can the above be solved in Python?
 Can you provide a code to minimum elements to be removed from the ends to make the array sorted and the other steps required?
assistant
#Here is code to minimum elements to be removed from the ends to make the array sorted and the other steps required.
 def findMin ( arr , n ) :
	ans = 1
	for i in range ( n ) :
		j = i + 1
		while ( j < n and arr [ j ] >= arr [ j - 1 ] ) :
			j += 1
		ans = max ( ans , j - i )
		i = j - 1
	return n - ans
arr = [ 3 , 2 , 1 ]
n = len ( arr )
print ( findMin ( arr , n ) )