human
Minimum number of swaps required to sort an array of first N number | Function to find minimum swaps.
Initialise count variable.
If current element is not at the right position.
Swap current element with correct position of that element.
Increment for next index when current element is at correct position.
Driver code.
Function to find minimum swaps"
Solution in Python:
assistant
#Here is code to minimum number of swaps required to sort an array of first N number and the other steps required.
 def minimumSwaps ( arr ) :
	count = 0 ;
	i = 0 ;
	while ( i < len ( arr ) ) :
		if ( arr [ i ] != i + 1 ) :
			while ( arr [ i ] != i + 1 ) :
				temp = 0 ;
				temp = arr [ arr [ i ] - 1 ] ;
				arr [ arr [ i ] - 1 ] = arr [ i ] ;
				arr [ i ] = temp ;
				count += 1 ;
		i += 1 ;
	return count ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 3 , 4 , 1 , 5 ] ;
	print ( minimumSwaps ( arr ) ) ;