Implement a function that checks for the presence of non-overlapping occurrences of the substrings "AB" and "BA" within a given string. The function should determine if the substrings "AB" and "BA" can exist in a non-overlapping manner.
The function should search for the first occurrence of the substring "AB" and the last occurrence of the substring "BA", as well as the first occurrence of "BA" and the last occurrence of "AB".
The function should return:
"YES" if "AB" and "BA" occur in a non-overlapping manner (meaning they do not share any characters and are not adjacent).
"NO" if:
Either "AB" or "BA" does not exist in the string.
The occurrences of "AB" and "BA" are adjacent or overlap.
Input
s (1 <= len(s) <= 100): A string that may contain uppercase letters.
Output
Returns a string "YES" or "NO" based on the above conditions.
Implementation
Write the function according to the signature and requirements in a file called /app/solution.py.