human
Find lexicographically smallest string in at most one swaps | Function to return the lexicographically smallest string that can be formed by swapping at most one character . The characters might not necessarily be adjacent ..
Set - 1 as default for every character ..
Character index to fill in the last occurrence array.
If this is true then this character is being visited for the first time from the last Thus last occurrence of this character is stored in this index.
Character to replace.
Find the last occurrence of this character ..
Swap this with the last occurrence swap ( s [ i ] , s [ last_occ ] ).
.
Driver code"
Solution in Python:

=====
What is a code to find lexicographically smallest string in at most one swaps and the other steps required?
assistant
#Here is code to find lexicographically smallest string in at most one swaps and the other steps required.
 def findSmallest ( s ) :
	length = len ( s ) ;
	loccur = [ - 1 ] * 26 ;
	for i in range ( length - 1 , - 1 , - 1 ) :
		chI = ord ( s [ i ] ) - ord ( ' a ' ) ;
		if ( loccur [ chI ] == - 1 ) :
			loccur [ chI ] = i ;
	sorted_s = s ;
	sorted_s . sort ( ) ;
	for i in range ( length ) :
		if ( s [ i ] != sorted_s [ i ] ) :
			chI = ord ( sorted_s [ i ] ) - ord ( ' a ' ) ;
			last_occ = loccur [ chI ] ;
			s [ i ] , s [ last_occ ] = s [ last_occ ] , s [ i ]
			break ;
	return " " . join ( s ) ;
if __name__ == " _ _ main _ _ " :
	s = " geeks " ;
	print ( findSmallest ( list ( s ) ) ) ;