How to approach this problem. My approach was to find the prfix from 0 to i and suffix from n — 1 to i + 1. concatenate both for a new string and find longest palindromic subsequence for the current string. But it gave wrong answer and later I realized that my approach will not work always.
Any other approach for this problem. The tag was dp for the problem.
Thanks.
I think it can be easily solved in O(|S|^3). Break S into two parts and find longest common subsequence b/w two parts. Answer will be maximum among all cases.
There are |S| ways to break and LCS can be solved in |S|^2.
Giving a complexity of n^3.