using longest common substring solution for solving longest palindrome substring
Clash 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);
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.
Any palindrome that occurs in
A
will also occur in the reversal ofA
, 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