human
Increasing permutation of first N natural numbers | Function that returns true if it is possible to make the permutation increasing by swapping any two numbers.
To count misplaced elements.
Count all misplaced elements.
If possible.
Driver code"
Solution in Python:
assistant
#Here is code to increasing permutation of first N natural numbers and the other steps required.
 def isPossible ( a , n ) :
	k = 0 ;
	for i in range ( n ) :
		if ( a [ i ] != i + 1 ) :
			k += 1 ;
	if ( k <= 2 ) :
		return True ;
	return False ;
if __name__ == " _ _ main _ _ " :
	a = [ 5 , 2 , 3 , 4 , 1 ] ;
	n = len ( a ) ;
	if ( isPossible ( a , n ) ) :
		print ( " Yes " ) ;
	else :
		print ( " No " ) ;