Trace word1 = "ab", word2 = "a".
Base cases: dp[0][0]=0, dp[1][0]=1, dp[2][0]=2, dp[0][1]=1.
i=1, j=1: word1[0]='a' == word2[0]='a'. Match! dp[1][1] = dp[0][0] = 0.
i=2, j=1: word1[1]='b' ≠ word2[0]='a'. No match. Insert: dp[2][0] + 1 = 3. Delete: dp[1][1] + 1 = 1. Replace: dp[1][0] + 1 = 2. dp[2][1] = min(3, 1, 2) = 1.
Answer: . Delete 'b' from "ab" to get "a".
time and space.