Asked at
Longest Common Subsequence
MediumVerifiedString MatchingDynamic Programming~25 min
A subsequence keeps order but may drop characters. Given strings text1 and text2, return the length of their longest common subsequence.
The input arrives as a single object { text1, text2 }. Return the length.
Examples
in{ text1: "abcde", text2: "ace" }
out3
"ace" is the longest common subsequence.
in{ text1: "abc", text2: "def" }
out0
No common subsequence.
Constraints
- 1 ≤ text1.length, text2.length ≤ 1000
- Inputs consist of lowercase English letters.
- Target: O(m · n) time
Get help
🔑
Sign in to solve
Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.