human
Find an anagram of given String having different characters at corresponding indices | Function to find anagram of string such that characters at the same indices are different.
Copying our original string for comparison.
Declaring the two pointers.
Checking the given condition.
When string length is odd.
The mid element.
If the characters are the same , then perform the swap operation as illustrated.
Check if the corresponding indices has the same character or not.
If string follows required condition.
Driver Code"
Solution in Python:
assistant
#Here is code to find an anagram of given String having different characters at corresponding indices and the other steps required.
 def findAnagram ( s ) :
	check = s
	st = list ( s )
	i = 0
	j = len ( st ) - 1
	while ( i < len ( st ) and j >= 0 ) :
		if ( st [ i ] != st [ j ] and check [ i ] != st [ j ] and check [ j ] != st [ i ] ) :
			st [ i ] , st [ j ] = st [ j ] , st [ i ]
			i += 1
			j = len ( st ) - 1
		else :
			j -= 1
	if ( len ( st ) % 2 != 0 ) :
		mid = len ( st ) / 2
		if ( check [ mid ] == st [ mid ] ) :
			for i in range ( len ( st ) ) :
				if ( check [ i ] != st [ mid ] and st [ i ] != st [ mid ] ) :
					st [ i ] , st [ mid ] = st [ mid ] , st [ i ]
					break
	ok = True
	for i in range ( len ( st ) ) :
		if ( check [ i ] == st [ i ] ) :
			ok = False
			break
	if ( ok ) :
		print ( " " . join ( st ) )
	else :
		print ( - 1 )
if __name__ == " _ _ main _ _ " :
	S = " geek "
	findAnagram ( S )