PIXELBANKv8.2.1
Menu

Longest Common Subsequence

Given two strings, return the length of their longest common subsequence (LCS). A subsequence maintains relative order but needn't be contiguous.

Example:

Input:
abcde
ace
Output:
3
Reasoning:
  • The two input strings are abcde and ace, and we need to find their longest common subsequence (LCS).
  • We compare the characters of both strings and find the common characters in the same relative order: a, c, and e.
  • The length of this LCS is 33, since it contains three characters.
  • The final output is the length of the LCS, which is 33.

Constraints:

  • 1 <= len(text1), len(text2) <= 1000
  • text1 and text2 consist of lowercase English letters
Editor

Test Results

0/0
Run code to see test results.