Search⌘ K
AI Features

Solution: Longest Common Subsequence

Solution: Longest Common Subsequence compares two strings and asks for the length of their longest shared subsequence, preserving the order of chosen characters in both, or zero if none exists.

Statement

Suppose you are given two strings. You need to find the length of the longest common subsequence between these two strings.

A subsequence is a string formed by removing some characters from the original string while maintaining the relative position of the remaining characters. For example, “abd” is a subsequence of “abcd”, where the removed character is “c”.

If there is no common subsequence, then return 0.

Constraints:

  • 1≤1 \leq str1.length ≤500\leq 500
...