I am getting RTE. Can someone tell me what I am doing wrong. I am using LCS to calculate the number of deletions


#1

int lcs(string a, int n)
{
string b = a;
reverse(b.begin(),b.end());

int t[n+1][n+1];
for(int i=0; i<=n; i++)
{
    for(int j=0; j<=n; j++)
    {
        if(i == 0 || j==0)
            t[i][j] = 0;
    }
}

for(int i=1; i<=n; i++)
{
    for(int j=1; j<=n; j++)
    {
        if(a[i-1] == b[j-1])
            {
                t[i][j] = 1+ t[i-1][j-1];
            }
        else
            {
                t[i][j] = max(t[i-1][j],t[i][j-1]);
            }
    }
}

return t[n][n];

}

int Solution::solve(string A) {

if(n <= 1)
    return 1;

int n = A.length();

int ans = n-lcs(A,n);

if(ans<=1)
    return 1;
return 0;

}