I just coded this today…the problem seems interesting. But after writing it I observer that there is no way I can check this. You know how it feels when you code and cannot verify whether it is correct/wrong. That’s why I am posting my code here in hope that someone will check my code and tell me whether it is correct or incorrect.
The pastebin link-
[1]
Edit-1: The problem link - [PROBLEM][2]
[1]: http://pastebin.com/LwjJdYkg
[2]: https://www.codechef.com/CWAR2015/problems/CWAR02
Incorrect. Your code doesn’t even work for the given example. The simplest testcase for which it is producing wrong result is
A
BA
Currently you are deciding whether to remove a A or a B by first trying A and if doesn’t work removing B. But you have to check both possibilities. If implemented efficiently this will work within the given constraints (use memoization!).