My solution passed all the tests but I found a nicer solution
The better solution works by saying that if the last letter is A, then we can only obtain target if we can obtain target(0, n-1). If the last letter is B then we can only obtain target if we can obtain reverse(target(0, n-1)).