20

Two Substrings

Difficulty: EASY
Avg. time to solve
10 min
Success Rate
85%

Problem Statement
Suggest Edit

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
Want to solve this problem? Login now to get access to solve the problems