Delete Operation for Two Strings
MediumDynamic Programming2d dp
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given two strings word1 and word2, you may delete one character from either string per step. Return the minimum number of deletions needed to make the two strings identical.
Two empty strings count as identical, so an answer always exists.
Examples
Input: word1 = "sea", word2 = "eat"
Output: 2
Delete "s" from "sea" and "t" from "eat"; both become "ea".
Input: word1 = "leetcode", word2 = "etco"
Output: 4
Delete four letters from "leetcode" to leave "etco".
Constraints
- `1 <= word1.length, word2.length <= 500`
- Both strings contain only lowercase English letters
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.