69. Longest Common Subsequence

Medium · Dynamic Programming

Find the length of the longest common subsequence (LCS) between two strings. A subsequence is a sequence that appears in the same order within a string, but not necessarily consecutively — for example, "ace" is a subsequence of "abcde" because those letters appear in order (with 'b' and 'd' skipped). Your function receives input as an array [text1, text2] containing two strings, and must return the length of their longest common subsequence as an integer.

Examples

Example 1
Input: ["abcde", "ace"]
Output: 3
Explanation: "ace" is a subsequence of "abcde"
Example 2
Input: ["abc", "def"]
Output: 0
Explanation: No common letters

Constraints