Edit Distance
LeetCode 72 • Hard • Dynamic Programming
Input: word1 = "horse", word2 = "ros" → Output: 3. DP[i][j] = min ops to convert word1[:i] to word2[:j].
TimeO(m×n)
SpaceO(m×n)
dp[i][j]: —
Current cell
Result
dp[i][j]—
Ready
Press Play. DP[i][j] = min(insert, delete, replace). Same char: dp[i-1][j-1]. Else: 1 + min of three.