Given two strings `text1` and `text2`, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
2D Dynamic Programming
We build a 2D matrix `dp[i][j]` representing the length of the longest common subsequence of `text1[i:]` and `text2[j:]`. - If `text1[i] == text2[j]`, then `dp[i][j] = 1 + dp[i+1][j+1]` (Characters match, move diagonally). - If `text1[i] != text2[j]`, then `dp[i][j] = max(dp[i+1][j], dp[i][j+1])` (Mismatch, try skipping one character from either string).