257. Edit Distance

HardStringString

Given two strings word1 and word2, return the minimum number of operations (insert, delete, or replace a single character) required to convert word1 into word2. Input: '"word1", "word2"'.

Input: '"word1", "word2"'.

Output: Integer — minimum edit operations.

Examples

Example 1
Input: "horse", "ros"
Output: 3
Explanation: horse->rorse->rose->ros.
Example 2
Input: "intention", "execution"
Output: 5
Explanation: Five operations.
Example 3
Input: "", "abc"
Output: 3
Explanation: Insert three characters.

Constraints

Asked by

SwiggyFlipkartAmazonInfosysBloombergDeloitte
Solve this problem in the editor →