Anish is given a string S and has been asked to determine if the given string S contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
As a friend of Anish, your task is to return “True” if the string S contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order) otherwise return “False” (without quotes).Example:-
The string “ABBA” has two non-overlapping substrings “AB” and “BA” respectively. So “True” will be printed(without quotes).
1 <= T <= 10 1 <= |S| <= 10^4 The string S contains uppercase Latin letters only. Time Limit = 1 sec
Sample Output 1 :
2 ABA BACFAB
Explanation for Sample Output 1 :
Sample Input 2 :
In the first test case, there are no two non-overlapping substrings, so “False” is printed. In the second test case, there are two non-overlapping substrings (BACFAB), so “True” is printed.
Sample Output 2 :
2 ABBA AXBYBXA