human
Minimum number of increment / decrement operations such that array contains all elements from 1 to N | Function to find the minimum operations.
Sort the given array.
Count operations by assigning a [ i ] = i + 1.
Driver Code"
Solution in Python:
 ... What is a code to minimum number of increment / decrement operations such that array contains all elements from 1 to N and the other steps required?
assistant
#Here is code to minimum number of increment / decrement operations such that array contains all elements from 1 to N and the other steps required.
 def minimumMoves ( a , n ) :
	operations = 0
	a . sort ( reverse = False )
	for i in range ( 0 , n , 1 ) :
		operations = operations + abs ( a [ i ] - ( i + 1 ) )
	return operations
if __name__ == ' _ _ main _ _ ' :
	arr = [ 5 , 3 , 2 ]
	n = len ( arr )
	print ( minimumMoves ( arr , n ) )