Problem · String
Longest Common Subsequence Length
Learn this problemProblem 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. The characters in a common subsequence must appear in both strings in the same relative order; they do not need to occupy consecutive positions.
Function
longestCommonSubsequence(first: String, second: String) → intExamples
Example 1
first = "abcde"second = "ace"return = 3The string ace appears in both inputs in the same relative order.
Example 2
first = "abc"second = "def"return = 0The two strings share no character, so the longest common subsequence is empty.
Constraints
0 <= first.length, second.length <= 1000firstandsecondcontain only lowercase English letters.