human
Can you provide a code to check if reversing a sub array make the array sorted and the other steps required given the following:
Check if reversing a sub array make the array sorted | Return true , if reversing the subarray will sort the array , else return false ..
Copying the array.
Sort the copied array ..
Finding the first mismatch ..
Finding the last mismatch ..
If whole array is sorted.
Checking subarray is decreasing or not ..
Driver code"
Solution in Python:
assistant
#Here is code to check if reversing a sub array make the array sorted and the other steps required.
 def checkReverse ( arr , n ) :
	temp = [ 0 ] * n
	for i in range ( n ) :
		temp [ i ] = arr [ i ]
	temp . sort ( )
	for front in range ( n ) :
		if temp [ front ] != arr [ front ] :
			break
	for back in range ( n - 1 , - 1 , - 1 ) :
		if temp [ back ] != arr [ back ] :
			break
	if front >= back :
		return True
	while front != back :
		front += 1
		if arr [ front - 1 ] < arr [ front ] :
			return False
	return True
arr = [ 1 , 2 , 5 , 4 , 3 ]
n = len ( arr )
if checkReverse ( arr , n ) == True :
	print ( " Yes " )
else :
	print ( " No " )