human
Check if two arrays can be made equal by reversing any subarray once | Function to check whether two arrays can be made equal by reversing a sub - array only once.
Integer variable for storing the required starting and ending indices in the array.
Finding the smallest index for which A [ i ] != B [ i ] i . e the starting index of the unequal sub - array.
Finding the largest index for which A [ i ] != B [ i ] i . e the ending index of the unequal sub - array.
Reversing the sub - array A [ start ] , A [ start + 1 ] . . A [ end ].
Checking whether on reversing the sub - array A [ start ] ... A [ end ] makes the arrays equal.
If any element of the two arrays is unequal print No and return.
Print Yes if arrays are equal after reversing the sub - array.
Driver code"
Solution in Python:
 ... Can you provide a code to check if two arrays can be made equal by reversing any subarray once and the other steps required?
assistant
#Here is code to check if two arrays can be made equal by reversing any subarray once and the other steps required.
 def checkArray ( A , B , N ) :
	start = 0
	end = N - 1
	for i in range ( N ) :
		if ( A [ i ] != B [ i ] ) :
			start = i
			break
	for i in range ( N - 1 , - 1 , - 1 ) :
		if ( A [ i ] != B [ i ] ) :
			end = i
			break
	A [ start : end + 1 ] = reversed ( A [ start : end + 1 ] )
	for i in range ( N ) :
		if ( A [ i ] != B [ i ] ) :
			print ( " No " )
			return
	print ( " Yes " )
if __name__ == ' _ _ main _ _ ' :
	A = [ 1 , 3 , 2 , 4 ]
	B = [ 1 , 2 , 3 , 4 ]
	N = len ( A )
	checkArray ( A , B , N )