DIY: Edit Distance
Solve the interview question "Edit Distance" in this lesson.
We'll cover the following
Problem statement
Given two strings, str1
and str2
, you have to return the minimum number of edit operations that are required to convert str1
to str2
.
Note: You are allowed to insert, delete, or replace characters for this conversion.
Input
The input will be two strings. Here are some examples of the input to the function:
// Sample Input 1:
str1 = "intention", str2 = "execution"
// Sample Input 2:
str1 = "abdca", str2 = "cbda"
// Sample Input 3:
str1 = "passport", str2 = "ppsspqrt"
Output
The output will be an integer. Here are some examples of the output:
// Sample Output 1:
5
// Sample Output 2:
2
// Sample Output 3:
2
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.