Let’s say I have a “target string” (or list, doesn’t really matter) of some length N. For simplicity’s sake, let’s say there are two and only two possible characters, “A” and “B”. So, for example, maybe the target string is “ABBABB”.
I am then given a test string of some length <= N (again, the same two possible characters). I want to determine whether or not the test string can be transformed into the target string under the constraint that the only legal transformation is the insertion of characters.
For example, let’s again say the target is ABBABB, and the test is BBB. Then the answer is yes, the test can be transformed into the target; for example: BBB -> BBAB -> ABBAB -> ABBABB.
But if the test were BABA, then it could not be transformed into the target, since the target begins with an A, the test does not, and inserting an A into the test won’t work because that would cause it to have more A’s than the target has.
Obviously, I could make this yes-or-no determination by brute force, plowing through all possible sequences of character insertions. But is there a more efficient way?
Thanks in advance.
At first glance, the simple answer seems to be if the test string is sequentially contained in the target string then your test passes.
Something like: