Why 2tc failed with this approach?

Consider the following case:
aabbaa answer should be a2b2a2 but your code is giving the answer a4b2