Print LCS Problem


It is not giving the correct output.

You are using the wrong printing function, modify your code as per this logic
if(X[i-1]==Y[j-1])
{
lcs[index-1]=X[i-1];
i–;
j–;
index–;
}
else
if(dp[i-1][j]>dp[i][j-1])
{
i–;
}
else
{
j–;
}

Hey @Kiransharma, you have made various mistakes like interchange in m and n. Moreover using string here for storing result also leads to wrong answer.
I have these changes on your code https://ide.codingblocks.com/s/80225 you can check them.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.