This is a problem from spoj. AIBOHP
The characters can be added anywhere in the string.
The simplest solution that I read stated as follows:
Find the Longest Common Subsequence of the string and it's reverse. The answer then is (length of the string - LCS of both strings). This kind of seems intuitive but I'm having a hard time proving it. I'm sorry if the question seems stupid but can someone clearly explain why this approach would always work.
Note: Questions related to this problem have been asked sometimes on Stack Overflow, but none of those seem to answer my question. This question is not duplicate, In this question an answer states this approach but nowhere is the intuition or the proof given and that's exactly what I am asking. I know how to solve it, I'm asking why this method works.