A subsequence keeps letters in order but may skip some. Fill a table where L[i,j] is the LCS length of the first i letters of A and the first j letters of B: each cell is one comparison plus a look at its neighbours, and a walk back from the corner recovers the letters.
- Average time
- O(mn)
- Space
- O(mn)