human
Lexicographically largest string formed in minimum moves by replacing characters of given String | Function to print the lexicographically the largest string obtained in process of obtaining a string containing first N lower case english alphabtes.
Store the frequency of each character.
Traverse the string S.
Stores the characters which are not appearing in S.
Stores the index of the largest character in the array V , that need to be replaced.
Traverse the string , S.
If frequency of S [ i ] is greater than 1 or it is outside the range.
Decrement its frequency by 1.
Update S [ i ].
Decrement j by 1.
Traverse the string , S.
Decrement its frequency by 1.
Update S [ i ].
Increment l by 1.
Return S.
Given Input.
Function Call"
Solution in Python:
assistant
#Here is code to lexicographically largest string formed in minimum moves by replacing characters of given String and the other steps required.
 def lexicographicallyMaximum ( S , N ) :
	M = { }
	for i in range ( N ) :
		if S [ i ] in M :
		M [ S [ i ] ] += 1
		else :
			M [ S [ i ] ] = 1
	V = [ ]
	for i in range ( ord ( ' a ' ) , ord ( ' a ' ) + min ( N , 25 ) ) :
		if i not in M :
			V . append ( chr ( i ) )
	j = len ( V ) - 1
	for i in range ( N ) :
		if ( ord ( S [ i ] ) >= ( ord ( ' a ' ) + min ( N , 25 ) ) or ( S [ i ] in M and M [ S [ i ] ] > 1 ) ) :
			if ( ord ( V [ j ] ) < ord ( S [ i ] ) ) :
				continue
			M [ S [ i ] ] -= 1
			S = S [ 0 : i ] + V [ j ] + S [ ( i + 1 ) : ]
			j -= 1
		if ( j < 0 ) :
			break
	l = 0
	for i in range ( N - 1 , - 1 , - 1 ) :
		if ( l > j ) :
			break
		if ( ord ( S [ i ] ) >= ( ord ( ' a ' ) + min ( N , 25 ) ) or S [ i ] in M and M [ S [ i ] ] > 1 ) :
			M [ S [ i ] ] -= 1
			S = S [ 0 : i ] + V [ l ] + S [ ( i + 1 ) : ]
			l += 1
	s = list ( S )
	s [ len ( s ) - 1 ] = ' d '
	S = " " . join ( s )
	return S
S = " abccefghh "
N = len ( S )
print ( lexicographicallyMaximum ( S , N ) )