Lcs

2 articles

dsa7 min read

Longest Common Subsequence — The 2D DP Template You Will Reuse Forever

LeetCode 1143 Longest Common Subsequence is the foundational two-string DP every FAANG interviewer expects you to nail. We derive the dp[i][j] recurrence, walk a full table, optimize space from O(m*n) to O(min(m,n)), and trace why this template powers Edit Distance, Shortest Common Supersequence, and diff tooling.

Read →