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)
- Construct a binary string following the given constraints
- Generate all permutations of a string that follow given constraints
- Minimum number of given operations required to convert a string to another string
- Convert string X to an anagram of string Y with minimum replacements
- Convert the string into palindrome string by changing only one character.
- Convert Hexadecimal value String to ASCII value String
- Minimum cuts required to convert a palindromic string to a different palindromic string
- String slicing in Python to check if a string can become empty by recursive deletion
- Check if a string can be converted to another string by replacing vowels and consonants
- Convert character array to string in C++
- Convert a String to Integer Array in C/C++
- Convert a String to an Integer using Recursion
- Convert string to char array in C++
- Convert String into Binary Sequence
- Check if a string can be obtained by rotating another string 2 places
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.
Improved By : ankush_953