using longest common substring solution for solving longest palindrome substring

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



using longest common substring solution for solving longest palindrome substring



I was trying to solved longest palindrome substring problem using longest common substring by reversing the main string.
But my algo is failing for below examples:



"abadefdaba"
expected outcome : aba
but i m getting output as abad.



Seems I am missing some condition in my program:


string longestPalindrome(string A)

int **dp = new int*[A.length()+1];
for(int i=0;i<=A.length();i++)
dp[i] = new int[A.length()];
string B = A;
reverse(B.begin(), B.end());
int res = INT_MIN;
int max_i = INT_MIN;
for(int i=0;i<= A.length();i++)

for(int j=0;j<=A.length();j++)

if(i==0


return A.substr(max_i-res,res);





Any palindrome that occurs in A will also occur in the reversal of A, but the converse is not true. Your program never checks to see whether its output is a palindrome.
– Joe Farrell
Aug 12 at 13:12


A


A









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard