Delete Operation for Two Strings

Medium

Description

Given two strings, return minimum number of steps to make them equal. Each step can delete one character from either string.

Examples

Input:word1 = "sea", word2 = "eat"
Output:2
Explanation:

Delete 's' from 'sea' and 't' from 'eat'.

Input:word1 = "a", word2 = "a"
Output:0
Explanation:

Edge case with a single character.

Input:word1 = "leetcode", word2 = "etco"
Output:4
Explanation:

The longest common subsequence is "etco" with length 4. The task requires delete 4 characters from "leetcode" (l, e, d, e) and 0 characters from "etco", totaling 4 deletions to make both strings equal to "etco".

Constraints

  • 1 ≤ word1.length, word2.length ≤ 500

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!