human
Write me a code to rearrange two given arrays such that sum of same indexed elements lies within given range and the other steps required given the following:
Rearrange two given arrays such that sum of same indexed elements lies within given range | Function to check if there exists any arrangements of the arrays such that sum of element lie in the range [ K / 2 , K ].
Sort the array arr1 [ ] in increasing order.
Sort the array arr2 [ ] in decreasing order.
Traverse the array.
If condition is not satisfied break the loop.
Print the result.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to rearrange two given arrays such that sum of same indexed elements lies within given range and the other steps required.
 def checkArrangement ( A1 , A2 , n , k ) :
	A1 = sorted ( A1 )
	A2 = sorted ( A2 )
	A2 = A2 [ : : - 1 ]
	flag = 0
	for i in range ( n ) :
		if ( ( A1 [ i ] + A2 [ i ] > k ) or ( A1 [ i ] + A2 [ i ] < k // 2 ) ) :
			flag = 1
			break
	if ( flag == 1 ) :
		print ( " No " )
	else :
		print ( " Yes " )
if __name__ == ' _ _ main _ _ ' :
	arr1 = [ 1 , 3 , 4 , 5 ]
	arr2 = [ 2 , 0 , 1 , 1 ]
	K = 6
	N = len ( arr1 )
	checkArrangement ( arr1 , arr2 , N , K )