human
Minimum De | function to count Dearrangement.
create a copy of original array.
sort the array.
traverse sorted array for counting mismatches.
reverse the sorted array.
traverse reverse sorted array for counting mismatches.
return minimum mismatch count.
Driven code"
How can the above be solved in Python?
assistant
#Here is code to minimum De and the other steps required.
 def countDe ( arr , n ) :
	i = 0
	v = arr . copy ( )
	arr . sort ( )
	count1 = 0
	i = 0
	while ( i < n ) :
		if ( arr [ i ] != v [ i ] ) :
			count1 = count1 + 1
		i = i + 1
	arr . sort ( reverse = True )
	count2 = 0
	i = 0
	while ( i < n ) :
		if ( arr [ i ] != v [ i ] ) :
			count2 = count2 + 1
		i = i + 1
	return ( min ( count1 , count2 ) )
arr = [ 5 , 9 , 21 , 17 , 13 ]
n = 5
print ( " Minimum ▁ Dearrangement ▁ = " , countDe ( arr , n ) )