bahiaya please check krna saara test case thik nhi aara
Longest common sequence
try to debug for test case:
ab
ba
correct answer: b
see this:
galat hi aara ha bhaiya
or jo given test case ha bss vohi galat aara ha baaki sab k lea correct output milra ha
yes i have provided you with the code
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.
this is the complete code:
https://ide.codingblocks.com/s/412129