Getting Wrong Answer while submitting


#1

Here is my Code:

int dp[1006][1006];
int visited[1006][1006]={0};
int lps(int l,int r,string A)
{
if(l==r)
{
return 1;
}
if(r<l)
{
return 0;
}
if(visited[l][r]==1)
{
return dp[l][r];
}
if(A[l]==A[r])
{
dp[l][r]=lps(l+1,r-1,A)+2;
}
else
{
dp[l][r]=max(lps(l+1,r,A),lps(l,r-1,A));
}
visited[l][r]=1;
return dp[l][r];
}

int Solution::solve(string A) {
int n=A.size();
int ans=lps(0,n-1,A);
return ans;
}

For testcase : “abaaddaabbedeedeacbcdcaaed”, when I run this as custom input I am getting the correct answer=14, but when I Submit it, it’s showing me 13.