Find the minimum number of deletions needed to make two strings equal.
You are given two strings word1 and word2. In one operation, you may delete exactly one character from either string.
Return the minimum number of deletions required so that the two strings become identical.
A string is considered identical when both strings have exactly the same sequence of characters after deletions.
Compute the smallest total number of deletions across both strings needed to make them equal.
word1 and word2.0 <= word1.length, word2.length <= 500word1 and word2 consist of lowercase English letters only.Example 1
Input
word1 = "sea", word2 = "eat"
Output
2
Explanation
Delete 's' from "sea" and 't' from "eat". Both strings become "ea".
Example 2
Input
word1 = "leetcode", word2 = "etco"
Output
4
Explanation
One optimal way is to keep the common subsequence "etco" and delete the other characters from "leetcode".
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.