Please check the following code for Bottom-Up approach for Longest common subsequence problem


I have put dp[m+1][n+1]={0); Still code is picking garbage values. Why??

Hello @sahilkhan2312000131 intitalise all the values in your dp array with the help of the two loops or I think you can try memset as well.

Can you explain why even after putting dp[m+1][n+1]={0); code is picking garbage?

@sahilkhan2312000131 this is because when you do like this all the places In the matrix doesn’t Initialise to 0. I think only the starting place will be Initialised as 0.
You can check this by printing the dp array after doing like this

is the code correct for the problem??

@sahilkhan2312000131 yes your codes logic is correct