You must starting the search from the index immediately following the first found occurrence for overlapping, like this:
y=input()
m=0
n='NO'
if y.find('AB')!=-1:
m=y.find('AB')
if y.find('BA',m+2)!=-1:
n='yes'
else :
n='NO'
print (n)