human
Give me a code to rearrange an array to make similar indexed elements different from that of another array and the other steps required given the following:
Rearrange an array to make similar indexed elements different from that of another array | Function to find the arrangement of array B [ ] such that element at each index of A [ ] and B [ ] are not equal.
Length of array.
Print not possible , if arrays only have single equal element.
Reverse array B.
Traverse over arrays to check if there is any index where A [ i ] and B [ i ] are equal.
Swap B [ i ] with B [ i - 1 ].
Break the loop.
Print required arrangement of array B.
Given arrays A [ ] and B [ ].
Function call"
How can the above be solved in Python?
assistant
#Here is code to rearrange an array to make similar indexed elements different from that of another array and the other steps required.
 def RearrangeB ( A , B ) :
	n = len ( A )
	if ( n == 1 and A [ 0 ] == B [ 0 ] ) :
		print ( - 1 )
		return
	for i in range ( n // 2 ) :
		t = B [ i ]
		B [ i ] = B [ n - i - 1 ]
		B [ n - i - 1 ] = t
	for i in range ( n - 1 ) :
		if ( B [ i ] == A [ i ] ) :
			B [ i ] , B [ i - 1 ] = B [ i - 1 ] , B [ i ]
			break
	for k in B :
		print ( k , end = " ▁ " )
A = [ 2 , 4 , 5 , 8 ]
B = [ 2 , 4 , 5 , 8 ]
RearrangeB ( A , B )