Longest Common Subsequence

Medium

Topics
StringDynamic Programming

Given two strings text1 and text2, return the length of their longest common subsequence (characters in order, not necessarily contiguous). Return 0 if none.

Example 1

Input:  text1 = "abcde", text2 = "ace"
Output: 3

Example 2

Input:  text1 = "abc", text2 = "def"
Output: 0

Constraints

  • 1 <= text1.length, text2.length <= 1000
  • Inputs consist of lowercase English letters.
Run ⌘' · Submit ⌘⏎