The Blind 75 Leetcode Series: Longest Common Subsequence
1143. Longest Common Subsequence
Given two strings
text1
andtext2
, return the length of their longest common subsequence. If there is no common subsequence, return0
.A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
For example,
"ace"
is a subsequence of"abcde"
.A common subsequence of two strings is a subsequence that is common to both strings.
We are given 2 strings. There can be some letters existing in both strings with same order. We want to see what’s the longest common subsequence we can find in these strings. Note that a subsequence is only valid if the orders do not change. This means we cannot rearrange the letters.
A few questions to ask before diving into the problem:
- are we only looking at lowercase alphabets like the examples present?
- what’s the longest possible string we are going to see?
- do common subsequences have to start from…