Given two strings contains three characters i.e ‘A’, ‘B ‘and ‘#’ only. Check whether it is possible to convert the first string into another string by performing following operations on string first.
1- ‘A’ can move towards Left only
2- ‘B’ can move towards Right only
3- Neither ‘A’ nor ‘B’should cross each other
If it is possible then print “Yes” otherwise “No”.
The first line of the input contains integer T denoting the number of test cases. For each test case, there are two strings inputs str1 & str2.
For each test case, the output is a string displaying YES or NO.
1. ‘A’ in str1 is right to the ‘A’ in str2 so ‘A’ of str1 can move easily towards the left because there is no ‘B’ on its left positions and for first ‘B’ in str1 is left to the ‘B’ in str2 so ‘B’ of str2 can move easily towards the right because there is no ‘A’ on its right positions and it is same for next ‘B’ so str1 can be easily converted into str2.
2.Here first ‘A’ in str1 is left to the ‘A’ in str2 and according to the condition, ‘A’ can’t move towards right. so str1 can’t be converted into str2.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.