human
Convert given string so that it holds only distinct characters | Function to return the index of the character that has 0 occurrence starting from index i.
If current character has 0 occurrence.
If no character has 0 occurrence.
Function to return the modified string which consists of distinct characters.
String cannot consist of all distinct characters.
Count the occurrences for each of the character.
Index for the first character that hasn 't appeared in the string.
If current character appeared more than once then it has to be replaced with some character that hasn 't occurred yet.
Decrement current character 's occurrence by 1.
Replace the character.
Update the new character ' s ▁ occurrence ▁ ▁ This ▁ step ▁ can ▁ also ▁ be ▁ skipped ▁ as ▁ ▁ we ' ll never encounter this character in the string because it has been added just now.
Find the next character that hasn 't occurred yet.
Driver code"
Solution in Python:
assistant
#Here is code to convert given string so that it holds only distinct characters and the other steps required.
 def nextZero ( i , occurrences ) :
	while i < 26 :
		if occurrences [ i ] == 0 :
			return i
		i += 1
	return - 1
def getModifiedString ( str ) :
	n = len ( str )
	if n > 26 :
		return " - 1"
	ch = str
	ch = list ( ch )
	occurrences = [ 0 ] * 26
	for i in range ( n ) :
		occurrences [ ord ( ch [ i ] ) - ord ( ' a ' ) ] += 1
	index = nextZero ( 0 , occurrences )
	for i in range ( n ) :
		if occurrences [ ord ( ch [ i ] ) - ord ( ' a ' ) ] > 1 :
			occurrences [ ord ( ch [ i ] ) - ord ( ' a ' ) ] -= 1
			ch [ i ] = chr ( ord ( ' a ' ) + index )
			occurrences [ index ] = 1
			index = nextZero ( index + 1 , occurrences )
	ch = ' ' . join ( ch )
	print ( ch )
if __name__ == " _ _ main _ _ " :
	str = " geeksforgeeks "
	getModifiedString ( str )