human
Find array with k number of merge sort calls | Python program to find an array that can be sorted with k merge sort calls ..
We make two recursive calls , so reduce k by 2..
Create an array with values in [ 1 , n ].
calling unsort function.
Driver code"
How can the above be solved in Python?
 ... Give me a code to find array with k number of merge sort calls and the other steps required?
assistant
#Here is code to find array with k number of merge sort calls and the other steps required.
 def unsort ( l , r , a , k ) :
	if ( k < 1 or l + 1 == r ) :
		return
	k -= 2
	mid = ( l + r ) // 2
	temp = a [ mid - 1 ]
	a [ mid - 1 ] = a [ mid ]
	a [ mid ] = temp
	unsort ( l , mid , a , k )
	unsort ( mid , r , a , k )
def arrayWithKCalls ( n , k ) :
	if ( k % 2 == 0 ) :
		print ( " NO ▁ SOLUTION " )
		return
	a = [ 0 for i in range ( n + 2 ) ]
	a [ 0 ] = 1
	for i in range ( 1 , n ) :
		a [ i ] = i + 1
	k -= 1
	unsort ( 0 , n , a , k )
	for i in range ( n ) :
		print ( a [ i ] , " ▁ " , end = " " )
n = 10
k = 17
arrayWithKCalls ( n , k )