i solved using recurstion but its giving tle
How can we use dp for strings in lcs problem
Hey @jha.aparna17
- Pass ur strings by reference otherwie it also takes time to get copied
- Now to memoize your solution see u have two variables changing in reccurence i and j , so u will need a 2d matrix dp[n1][n2] where n1 and n2 are size of strings resp.
Hey @jha.aparna17
ans.pop_back();
reverse(ans.begin(),ans.end());
You answer contained a space ,so removed that
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.