My idea is to find the Length of Longest Palindromic subsequence and subtract it from the string length. Will it work. If no please give an explanation?
find the Length of Longest Palindromic subsequence and subtract it from the string length.
This will work obviously.
Another way can be - reverse the original string s
into s'
and find the LCS (longest common subsequence) of s
and s'
. The answer is: length(s) - LCS(s, s')