word1
and word2
into a single string word
.dp
with dimensions [n][n]
where n
is the length of word
.dp
array with the base case: dp[i][i] = 1
for all i
.dp
array for all substrings of word
.word1
, find the corresponding character in word2
and use the dp
array to find the LPS between these indices.word1
and word2
.