human
Minimum cost to make an Array a permutation of first N natural numbers | Function to calculate minimum cost for making permutation of size N.
sorting the array in ascending order.
To store the required answer.
Traverse the whole array.
Return the required answer.
Driver code.
Function call"
How can the above be solved in Python?
assistant
#Here is code to minimum cost to make an Array a permutation of first N natural numbers and the other steps required.
 def make_permutation ( arr , n ) :
	arr . sort ( ) ;
	ans = 0 ;
	for i in range ( n ) :
		ans += abs ( i + 1 - arr [ i ] ) ;
	return ans ;
if __name__ == " _ _ main _ _ " :
	arr = [ 5 , 3 , 8 , 1 , 1 ] ;
	n = len ( arr ) ;
	print ( make_permutation ( arr , n ) ) ;