Given two strings contains three characters i.e ‘A’, ‘B ‘and ‘#’ only. Check is it possible to convert 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’ cross each other
If it is possible then print “Yes” otherwise “No”.
Input : str1=” #A#B#B# “, str2=” A###B#B ”
‘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.
Input :str1=” #A#B# “, str2=” #B#A# ”
Here first ‘A’ in str1 is left to the ‘A’ in str2 and according to the condition ‘A’ can’tmove towards right. so str1 can’t be converted into str2.
1-Length of Both string must be same
2-No. of A’s and B’s in both the strings must be equal
3-Order of A and B in both the strings should be same(for ex: if ‘A’ is coming before ‘B’in string second then the same sequence must be follow on string first)
Time Complexity : O(n^2)
- Program to print the initials of a name with the surname
- Word Wrap problem ( Space optimized solution )
- Cost to Balance the parantheses
- Converting one string to other using append and delete last operations
- Check if it is possible to transform one string to another
- Smallest number with sum of digits as N and divisible by 10^N
- Count subsequences in first string which are anagrams of the second string
- Find the arrangement of queue at given time
- Identify and mark unmatched parenthesis in an expression
- Ways of transforming one string to other by removing 0 or more characters
- How to prepare for ACM - ICPC?
- Converting Decimal Number lying between 1 to 3999 to Roman Numerals
- Remove extra spaces from a string
- An in-place algorithm for String Transformation
- Print all interleavings of given two strings
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.