human
Sorting array with reverse around middle | Python 3 program to find possibility to sort by multiple subarray reverse operarion.
making the copy of the original array.
sorting the copied array.
checking mirror image of elements of sorted copy array and equivalent element of original array.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to sorting array with reverse around middle and the other steps required.
 def ifPossible ( arr , n ) :
	cp = [ 0 ] * n
	cp = arr
	cp . sort ( )
	for i in range ( 0 , n ) :
		if ( not ( arr [ i ] == cp [ i ] ) and not ( arr [ n - 1 - i ] == cp [ i ] ) ) :
			return False
	return True
arr = [ 1 , 7 , 6 , 4 , 5 , 3 , 2 , 8 ]
n = len ( arr )
if ( ifPossible ( arr , n ) ) :
	print ( " Yes " )
else :
	print ( " No " )