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.

1 Like

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â€¦

3 Likes