The DP (dynamic programming) gives you the length. To find the actual LCS (Longest Common Subsequence), backtrack from :
If A[i-1] = B[j-1], this character is in the LCS. Add it, move to .
If , move to .
Otherwise, move to .
Stop when you hit row 0 or column 0. Reverse the collected characters to get the LCS. Multiple valid LCS may exist if there are ties. Understanding this concept will help you solve more complex problems.