human
Write me a code to check if it is possible to sort an array with conditional swapping of adjacent allowed and the other steps required given the following:
Check if it is possible to sort an array with conditional swapping of adjacent allowed | Returns true if it is possible to sort else false /.
We need to do something only if previousl element is greater.
If difference is more than one , then not possible.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to check if it is possible to sort an array with conditional swapping of adjacent allowed and the other steps required.
 def checkForSorting ( arr , n ) :
	for i in range ( 0 , n - 1 ) :
		if ( arr [ i ] > arr [ i + 1 ] ) :
			if ( arr [ i ] - arr [ i + 1 ] == 1 ) :
				arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]
			else :
				return False
	return True
arr = [ 1 , 0 , 3 , 2 ]
n = len ( arr )
if ( checkForSorting ( arr , n ) ) :
	print ( " Yes " )
else :
	print ( " No " )