Medium · Dynamic Programming

Longest Common Subsequence

Given two strings text1 and text2, return the length of their longest common subsequence: the longest sequence of characters that appears in both strings in the same relative order, not necessarily contiguously (0 if they share no character).

Examples

Example 1

{
  "a": "abcde",
  "b": "ace"
}

Output: LCS = 3

Example 2

{
  "a": "abc",
  "b": "abc"
}

Output: LCS = 3

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Dynamic Programming problems