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)
- Check if it is possible to transform one string to another
- Remove minimum characters from string to split it into three substrings under given constraints
- Print array of strings in sorted order without copying one string into another
- Convert the string into palindrome string by changing only one character.
- Minimum swaps required to convert one binary string to another
- Minimum number of subsequences required to convert one string to another
- Minimum number of subsequences required to convert one string to another using Greedy Algorithm
- Minimum number of given operations required to convert a string to another string
- Check if one string can be converted to another
- Check if permutaion of one string can break permutation of another
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Check if the Matrix follows the given constraints or not
- Find length of longest subsequence of one string which is substring of another string
- Split the string into minimum parts such that each part is in the another string
- Construct a binary string following the given constraints
- Find value after N operations to remove N characters of string S with given constraints
- Generate all permutations of a string that follow given constraints
- Transform One String to Another using Minimum Number of Given Operation
- Convert given string to another by minimum replacements of subsequences by its smallest character
- Minimum substring flips required to convert given binary string to another
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.