Print longest common subsequences

please help me to find my one test case which is getting wrong here…?

Hi @nikhilmeena, in your function you have to consider some other cases like
when
dp[i-1][j]!=dp[i][j-1] && dp[i][j] != dp[i-1][j]&& dp[i][j]!=dp[i][j-1]
also inside

else if(dp[i-1][j]==dp[i][j-1]&&dp[i-1][j]==dp[i][j])
 {
     i=i-1;
 }

here it can happen that i-1 will lead to different string and the answer would be reached doing j-1
your algo is bit complicated

let me provide a easier algo:

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. and do i-- and j–

Else compare values of dp[i-1][j] and dp[i][j-1] and go in direction of greater value.

if (X[i-1] == Y[j-1]) 
{ 
    // Put current character in result 
    dp[index-1] =X[i-1];  

    // reduce values of i, j and index 
    i--;  
    j--;  
    index--;      
} 

// If not same, then find the larger of two and 
// go in the direction of larger value 
else if (dp[i-1][j] > L[i][j-1]) 
    i--; 
else
    j--;  

It would be better if you will try to implement this urself . In case of any doubt feel free to ask :wink:
If you got the answer then mark your doubt as resolved