Longest palindromic substring in the given string?

algorithm
dps
optimization
string

#1

Can anyone explain how do we find the longest palindromic sub string of in the given string. I know this is the standard DP problem, so please provide the proper DP explanation including overlapping sub-problems and optimal substructure, recursive solution and also what do we need to memorize.


#2

Well, if you only want the dp solution, You may refer This article. It explains in detail the basic state, transition and filling up the dp array.

But there are better approach for this problem, like here with same time complexity, but improved space complexity here.

If you want a really faster approach, like for string with length greater than 1000, you would like to have a look at manacher’s algorithm, a linear time algorithm for your prob here.

Hope this helps…

Please Upvote if u find this hepful…