Printing is wrong but length of lcs comes out is correct

@rohitkandpal683
you are doing i–,j-- and then adding s+= a[i-1]

https://ide.codingblocks.com/s/253648 3 test cases pass and 1 fail

@rohitkandpal683

if(a[i-1]==b[j-1]){
         s+=a[i-1];
         i--;
         j--;
     }
     else if(dp[i-1][j]>dp[i][j-1]){
         i--;
     }
     else{
         j--;
     }

you had to else if, you were doing if.

thanks for solving all my dp related doubts now it code works

1 Like