human
Lexicographically next greater string using same character set | function to print output.
to store unique characters of the string.
to check uniqueness.
if mp [ s [ i ] ] = 0 then it is first time.
sort the unique characters.
simply add n - k smallest characters.
searching the first character left of index k and not equal to greatest character of the string.
finding the just next greater character than s [ i ].
suffix with smallest character.
if we reach here then all indices to the left of k had the greatest character.
Driver code.
Function call"
Solution in Python:
assistant
#Here is code to lexicographically next greater string using same character set and the other steps required.
 def lexoString ( s , k ) :
	n = len ( s )
	v = [ ]
	mp = { s [ i ] : 0 for i in range ( len ( s ) ) }
	for i in range ( len ( s ) ) :
		if ( mp [ s [ i ] ] == 0 ) :
			mp [ s [ i ] ] = 1
			v . append ( s [ i ] )
	v . sort ( reverse = False )
	if ( k > n ) :
		print ( s , end = " " )
		for i in range ( n , k , 1 ) :
			print ( v [ 0 ] , end = " " )
		return ;
	i = k - 1
	while ( i >= 0 ) :
		if ( s [ i ] != v [ len ( v ) - 1 ] ) :
			for j in range ( 0 , i , 1 ) :
				print ( s [ j ] , end = " ▁ " )
			for j in range ( 0 , len ( v ) , 1 ) :
				if ( v [ j ] > s [ i ] ) :
					print ( v [ j ] , end = " ▁ " )
					break
			for j in range ( i + 1 , k , 1 ) :
				print ( v [ 0 ] , end = " ▁ " )
			re1turn
		i -= 1
	print ( " No ▁ lexicographically ▁ greater " , " string ▁ of ▁ length " , k , " possible ▁ here . " )
if __name__ == ' _ _ main _ _ ' :
	s = " gi "
	k = 3
	lexoString ( s , k )