Two Substrings Problem
Two Substrings Problem — ExecCode Medium DSA Practice
Solve the Two Substrings problem on ExecCode. Free online medium DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.
Problem description
You are given a string s made of uppercase English letters. Return YES if s contains both AB and BA as substrings of length 2 that do not share a character. Otherwise return NO. You are given: s — the string Return YES or NO. The two pieces may appear in either order. They may not overlap. ABA contains both patterns only by sharing the middle character, so it is NO.
Examples
Input {'s': 'ABBA'}; Output YES. Input {'s': 'ABA'}; Output NO. Input {'s': 'BAAB'}; Output YES
Constraints
1 <= s.length <= 100000 s contains only uppercase English letters
Practice Two Substrings free on ExecCode. Browse DSA problems, topic map, and placement guides.