https://ide.codingblocks.com/s/200974 one test case failing… please see the problem in the code
Print LCS problem
@Bansaljatin05
hello jatin
ur algorithm for printing lcs is not correct.
pls refer this algorithm,
Following is a detailed algorithm to print the LCS. It uses the same DP table that was calculated using count LCS program.
-
Construct dp[m+1][n+1] using the count LCS dynamic programming solution.
-
The value dp[m][n] contains length of LCS. Create a character array lcs[] of length equal to the length of lcs plus 1 (one extra to store \0).
-
Traverse the 2D array starting from dp[m][n]. Do following for every cell dp[i][j]
If characters (in X and Y) corresponding to dp[i][j] are same (Or X[i-1] == Y[j-1]), then include this character as part of LCS.
Else compare values of dp[i-1][j] and dp[i][j-1] and go in direction of greater value.
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.