The Blind 75 Leetcode Series: Longest Common Subsequence

Jonathan Chao
4 min readNov 15, 2023
Photo by Chris Ried on Unsplash

1143. Longest Common Subsequence

Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

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:

  1. are we only looking at lowercase alphabets like the examples present?
  2. what’s the longest possible string we are going to see?
  3. do common subsequences have to start from…

--

--

Jonathan Chao
Jonathan Chao

Written by Jonathan Chao

I am a software developer who has been in this industry for close to a decade. I share my experience to people who are or want to get into the industry

No responses yet