Mapped String Problem(recursion)

The code seems to run on my random test cases. But fails for two test cases on the portal. The logic seems to right. Please check
Link: https://ide.codingblocks.com/s/78640