Medium

Quiz

#583 Delete Operation for Two Strings

APPROACH

Given two strings word1 and word2, return the fewest total character deletions (one deletion per step, applied to either string) needed to make the two strings identical.

Example 1:

Input: word1 = "sea", word2 = "eat"
Output: 2
Explanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea".

Example 2:

Input: word1 = "leetcode", word2 = "etco"
Output: 4
1 of 4
1:00

What is the optimal approach for this problem?