You are given a string S. Your task is to determine if the given string S contains two non-overlapping substrings “AB” and “BA” (the substrings can go in any order). Print “YES” or “NO”.
The string S contains uppercase Latin letters only.
Input Format :
Line 1: String S
Output Format :
YES or NO
Constraints :
1 <= n (Length of String s) <= 10^5
Sample Input 1 :
ABA
Sample Output 1 :
NO
Sample Input 2 :
BACFAB
Sample Output 2 :
YES
Sample Input 3 :
AXBYBXA
Sample Output 3 :
NO
Code:
https://ide.geeksforgeeks.org/XdSeuh1S6T
Doubt in two substrings problems
hello @anitagupta1411
the question says that string can be in any order.
for example
BAXAB is also correct (BA and AB) but all u r checing only this case(AB and BA )
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.