Two substrings
Level EASY
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 :
Output format :
Constraints :
1 <= n (Length of String s) <= 10^5
Sample Input 1 :
Sample Output 1 :
Sample Input 2 :
Sample Output 2 :
Sample Input 3 :
Sample Output 3 :
no
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
x=s.find("AB") | |
y=s.find("BA",x+2) | |
i=s.find("BA") | |
j=s.find("AB",i+2) | |
if x>-1 and y>-1: | |
print("yes") | |
elif i>-1 and j>-1: | |
print("yes") | |
else:print("no") |
Comments
Post a Comment
Please give us your valuable feedback