Minimum Deletions to Make Two Strings Equal

Given two strings word1 and word2, return the minimum number of deletions required to make the two strings equal. You may delete characters from either string, and the final strings must be identical. Pattern focus: LCS. The answer is derived from the longest common subsequence length.

Input Format

word1 = first string, word2 = second string

Output Format

minimum number of deletions

Constraints

  • 0 <= word1.length, word2.length <= 1000
  • word1 and word2 contain lowercase English letters.

Examples

Example 1:

Input:

word1 = "sea"
word2 = "eat"

Output:

2

Explanation:

Delete s from sea and t from eat.

Example 2:

Input:

word1 = "abc"
word2 = "abc"

Output:

0

Explanation:

The strings are already equal.

Loading...
Minimum Deletions to Make Two Strings Equal