cheetcode

112. Longest Common SubsequenceMedium

Find the length of the longest subsequence shared by two strings.

Given two strings text1 and text2, return the length of their longest common subsequence.

A subsequence keeps the relative order of characters but does not need to be contiguous.

Examples

Input: text1 = "abcde", text2 = "ace"
Output: 3
Input: text1 = "abc", text2 = "def"
Output: 0

Constraints

  • 1 <= text1.length, text2.length <= 1000
  • text1 and text2 consist of lowercase English letters.