Back to DSA
Edit Distance
hardGiven two strings, determine the fewest single-character operations needed to transform the first string into the second. The permitted operations are inserting a character, removing a character, and substituting one character for another.
Examples
Example 1:
Input:
word1 = "kitten", word2 = "sitting"Output:
3Explanation: kitten -> sitten (substitute k with s) -> sittin (substitute e with i) -> sitting (insert g).
Example 2:
Input:
word1 = "abc", word2 = "yabd"Output:
2Explanation: abc -> yabc (insert y at front) -> yabd (substitute c with d).
Hints
1234567