human
Lexicographically smaller string by swapping at most one character pair | Function that finds whether is it possible to make string A lexicographically smaller than string B.
Condition if string A is already smaller than B.
Sorting temp string.
Condition for first changed character of string A and temp.
Condition if string A is already sorted.
Finding first changed character from last of string A.
Swap the two characters.
Condition if string A is smaller than B.
Driver Code"
Solution in Python:
assistant
#Here is code to lexicographically smaller string by swapping at most one character pair and the other steps required.
 def IsLexicographicallySmaller ( A , B ) :
	if ( A < B ) :
		return True
	temp = A
	temp = ' ' . join ( sorted ( temp ) )
	index = - 1
	for i in range ( len ( A ) ) :
		if ( A [ i ] != temp [ i ] ) :
			index = i
			break
	if ( index == - 1 ) :
		return False
	j = 0
	for i in range ( len ( A ) ) :
		if ( A [ i ] == temp [ index ] ) :
			j = i
	A = list ( A )
	A [ index ] , A [ j ] = A [ j ] , A [ index ]
	A = ' ' . join ( A )
	if ( A < B ) :
		return True
	else :
		return False
A = " AGAIN "
B = " ACTION "
if ( IsLexicographicallySmaller ( A , B ) ) :
	print ( " Yes " )
else :
	print ( " No " )