Resource · Guide or article
Longest common subsequence problem
Defines the longest common subsequence problem and how it differs from longest common substring, a classic DP interview question.
Reviewed
Open the original: Longest common subsequence problem (opens the original site in a new tab)Add to a roadmap
Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.
Source content: English
The longest common subsequence (LCS) problem is the problem of finding the longest subsequence common to all sequences in a set of sequences (often just two sequences). It differs from the longest common substring problem: unlike substrings, subsequences are not required to occupy consecutive positions within the original sequences. The longest common subsequence problem is a classic computer science problem, the basis of data comparison programs such as the diff utility, and has applications in bioinformatics. It is also widely used by revision control systems such as Git for reconciling multiple changes made to a revision-controlled collection of files.
PrepKit overview
PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.
- Suited to
- The source does not state a level
- Format
- Reference
What it covers
- Subsequence versus substring distinction.
- Applications such as diff tools, bioinformatics, and version control.
- Two examples with their LCS and lengths.
How to use it
PrepKit study advice, not a claim made by the source.
Fill the LCS table for ABCDGH and AEDFHR by hand, recover ADH, then code it.
Scope and limitations
No solution method or complexity is given; you need the linked Wikipedia page or video for that.
Access and format
English README, free on GitHub (trekhleb/javascript-algorithms, MIT).
Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88
Evidence behind this overview
- src/algorithms/sets/longest-common-subsequence/README.md
Pages that include this
Get the PrepKit newsletter
Optional. You don't need it to use PrepKit.