444iq's blog

By 444iq, history, 4 years ago, In English

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.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

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.