Longest Common Subsequence Length
Problem statement
Given two lowercase strings first and second, return the length of their longest common subsequence.
A subsequence is formed by deleting zero or more characters without changing the relative order of the remaining characters. A common subsequence appears in both strings; its characters do not need to be consecutive.
Function
longestCommonSubsequence(first: String, second: String) → intExamples
Example 1
first = "abcde"second = "ace"return = 3The subsequence ace appears in both strings.
Example 2
first = "abc"second = "def"return = 0The strings have no character in common.
Example 3
first = ""second = "abc"return = 0An empty string has no nonempty subsequence.
Constraints
0 <= first.length, second.length <= 1000- Both strings contain only lowercase English letters.