human
Count of elements which are not at the correct position | Function to return the count of elements which are not in the correct position when sorted.
To store a copy of the original array.
Copy the elements of the given array to the new array.
To store the required count.
Sort the original array.
If current element was not at the right position.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count of elements which are not at the correct position and the other steps required.
 def cntElements ( arr , n ) :
	copy_arr = [ 0 ] * n
	for i in range ( n ) :
		copy_arr [ i ] = arr [ i ]
	count = 0
	arr . sort ( )
	for i in range ( n ) :
		if ( arr [ i ] != copy_arr [ i ] ) :
			count += 1
	return count
arr = [ 1 , 2 , 6 , 2 , 4 , 5 ]
n = len ( arr )
print ( cntElements ( arr , n ) )