Printing lcs string using recursive dp

can any one give me the code for the lcs string print , bcz i asked this same doubt here then he is telling i’ll give you the code but still i’m not getting my ans

hey @ankit_verma here’s the code for LCS


but i would prefer you to only take it for reference and code it yourself :smile:

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.

no it’s it’s an iterative DP solution I want to take recursive solution for printing string

i already know this solution

You won’t be able to keep track of your i,j while doing recursion. Iterative will be only way to track your string as I mentioned above

ok,so this is the only approach for solving that question

Yes , cause while doing recursion you won’t be able to judge which character is to be inserted or not. And it will be a challenging problem too.

so please look into this code

Yes, you made it right. Now try to store it in any vector or array and then print it.

i do that thing also but didn’t got accepting all test cases.
i don’t know why this is?

Your do logic is correct, but they way you are printing it won’t be successful for every time. Try some of your own test cases.

1 Like