Introduction to String DP

Sequences, alignment, transformation

How does your spell checker suggest corrections? How does git diff align old and new files? These problems compare two strings character by character, finding optimal alignments or transformations.

String DP tracks position in one or more strings. Your state is usually dp[i][j]dp[i][j]: the answer for the first ii characters of string A and first jj of string B. I'll show you alignment problems, palindrome partitioning, pattern matching, and counting distinct subsequences.

unnamed - 2026-01-20T070522.630.jpg