dp with dimensions (len(word1) + 1) x (len(word2) + 1) and fill it with zeros.word1 and word2 using two nested loops.dp[i][j] to dp[i-1][j-1] + 1.dp[i][j] to the maximum of dp[i-1][j] and dp[i][j-1].dp array, the length of the LCS will be at dp[len(word1)][len(word2)].len(word1) + len(word2) - 2 * dp[len(word1)][len(word2)].