Dynamic Programming21 sections · 916 units
Open in Course

Intro

The Goal

LIS (Longest Increasing Subsequence) operates on one sequence. But what if you have two sequences and want to find what they share? Or convert one into another? You need to track position in both sequences simultaneously.

Your state becomes dp[i][j]dp[i][j]: some property involving the first ii characters of string A and the first jj characters of string B. By the end, you'll solve LCS (Longest Common Subsequence) and Edit Distance. These two problems are the foundation of spell checkers, diff tools, and DNA sequence alignment.