human
Write me a code to check if a string can be converted to another by swapping of adjacent characters of given type and the other steps required given the following:
Check if a string can be converted to another by swapping of adjacent characters of given type | Function to check if it is possible to transform start to end.
Check the sequence of A , B in both strings str1 and str2.
If both the strings are not equal.
Traverse the strings.
Check for indexes of A and B.
Driver Code.
Function call"
Solution in Python:
assistant
#Here is code to check if a string can be converted to another by swapping of adjacent characters of given type and the other steps required.
 def canTransform ( str1 , str2 ) :
	s1 = " "
	s2 = " "
	for c in str1 :
		if ( c != ' C ' ) :
			s1 += c
	for c in str2 :
		if ( c != ' C ' ) :
			s2 += c
	if ( s1 != s2 ) :
		return False
	i = 0
	j = 0
	n = len ( str1 )
	while ( i < n and j < n ) :
		if ( str1 [ i ] == ' C ' ) :
			i += 1
		elif ( str2 [ j ] == ' C ' ) :
			j += 1
		else :
			if ( ( str1 [ i ] == ' A ' and i < j ) or ( str1 [ i ] == ' B ' and i > j ) ) :
				return False
			i += 1
			j += 1
	return True
if __name__ == ' _ _ main _ _ ' :
	str1 = " BCCABCBCA "
	str2 = " CBACCBBAC "
	if ( canTransform ( str1 , str2 ) ) :
		print ( " Yes " )
	else :
		print ( " No " )