We're given a single string and asked to find two non-overlapping
substrings AB
and BA
(in either order). This
is a perfect problem to show off a regex, but unfortunately it is just
too slow. However, the dumb approach works beautifully. This code
could certainly be cleaned up, but if it's fast to write and correct,
who cares.