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 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
- Convert character array to string in C++
- Convert a String to an Integer using Recursion
- Convert a String to Integer Array in C/C++
- Convert String into Binary Sequence
- Convert string to char array in C++
- Convert characters of a string to opposite case
- Minimum cost to convert string into palindrome
- Convert a string to hexadecimal ASCII values
- Convert given string so that it holds only distinct characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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