Given two strings word1 and word2, you need to find the minimum number of deletion operations required to make both strings identical.
In one operation, you can delete exactly one character from either string. Your goal is to transform both strings into the same final string using the fewest possible deletions.
Example: If word1 = "sea" and word2 = "eat", you can delete 's' from "sea" and 't' from "eat" to get "ea" in both cases, requiring 2 deletions total.
The key insight is that the optimal solution preserves the longest common subsequence between the two strings, as these characters don't need to be deleted from either string.
Input & Output
Visualization
Time & Space Complexity
Fill each cell in the mรn table exactly once
2D DP table stores results for all subproblems
Constraints
- 1 โค word1.length, word2.length โค 500
- word1 and word2 consist of only lowercase English letters
- The answer will always fit in a 32-bit integer