human
Find the resultant String after replacing X with Y and removing Z | Function to replace and remove.
Two pointer start and end points to beginning and end position in the string.
If start is having Z find X pos in end and replace Z with another character.
Find location for having different character instead of Z.
If found swap character at start and end.
Else increment start Also checkin for X at start position.
Driver code"
Solution in Python:
assistant
#Here is code to find the resultant String after replacing X with Y and removing Z and the other steps required.
 def replaceRemove ( s , X , Y , Z ) :
	s = list ( s ) ;
	start = 0 ;
	end = len ( s ) - 1 ;
	while ( start <= end ) :
		if ( s [ start ] == Z ) :
			while ( end >= 0 and s [ end ] == Z ) :
				end -= 1 ;
			if ( end > start ) :
				s [ start ] , s [ end ] = s [ end ] , s [ start ]
				if ( s [ start ] == X ) :
					s [ start ] = Y ;
				start += 1
		else :
			if ( s [ start ] == X ) :
				s [ start ] = Y ;
			start += 1 ;
	while ( len ( s ) > 0 and s [ len ( s ) - 1 ] == Z ) :
		s . pop ( ) ;
	return " " . join ( s )
if __name__ == " _ _ main _ _ " :
	string = " batman " ;
	X = ' a ' ; Y = ' d ' ; Z = ' b ' ;
	string = replaceRemove ( string , X , Y , Z ) ;
	if ( len ( string ) == 0 ) :
		print ( - 1 ) ;
	else :
		print ( string ) ;