Guided Lesson Notes
Understanding Longest Common Subsequence
Longest Common Subsequence focuses on overlapping subproblems, reusable answers, and turning recursion into a table or memo. Longest common subsequence is a classic DP problem that compares two sequences while allowing skipped characters.
The mental model is this: define one state as a smaller question whose answer can help build larger answers. That picture matters because it tells the student what information is available immediately and what must be searched, stored, or recomputed.
The core invariant is that when a state is used, every smaller state it depends on must already be correct or memoized. If a solution cannot state that rule, the code may still run on a sample input but fail on edge cases.
A strong implementation usually uses state definitions, recurrence formulas, base cases, table order, memoization maps, and reconstruction when needed. The goal is not just to memorize an API; the goal is to know why each operation is allowed and what it costs.
In competitive programming, Longest Common Subsequence tends to appear when the problem asks for best, count, longest, shortest, ways, or choices over prefixes, positions, capacities, or subsets. Spotting that signal is often the difference between a nested-loop solution and an efficient one.
