human
What is a code to next word that does not contain a palindrome and has characters from first k and the other steps required given the following:
Next word that does not contain a palindrome and has characters from first k | Function to return lexicographically next word.
we made m as m + 97 that means our required string contains not more than m + 97 ( as per ASCII value ) in it ..
increment last alphabet to make next lexicographically next word ..
if i - th alphabet not in first k letters then make it as " a " and then increase ( i - 1 ) th letter.
to check whether formed string palindrome or not ..
increment i ..
if i less than or equals to one that means we not formed such word ..
Driver code"
Solution in Python:
assistant
#Here is code to next word that does not contain a palindrome and has characters from first k and the other steps required.
 def findNextWord ( s , m ) :
	m += 97
	n = len ( s )
	i = len ( s ) - 1
	s [ i ] = chr ( ord ( s [ i ] ) + 1 )
	while i >= 0 and i <= n - 1 :
		if ord ( s [ i ] ) >= m :
			s [ i ] = ' a '
			i -= 1
			s [ i ] = chr ( ord ( s [ i ] ) + 1 )
		elif s [ i ] == s [ i - 1 ] or s [ i ] == s [ i - 2 ] :
			s [ i ] = chr ( ord ( s [ i ] ) + 1 )
		else :
			i += 1
	if i <= - 1 :
		print ( " - 1" )
	else :
		print ( ' ' . join ( s ) )
if __name__ == " _ _ main _ _ " :
	string = " abcd "
	k = 4
	findNextWord ( list ( string ) , k )