PIXELBANKv9.1.0
Menu

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
  • Strings consist of lowercase English letters
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.