Edit Distance Problem Statement
Given two strings S
and T
with lengths N
and M
respectively, your task is to find the "Edit Distance" between these strings.
The Edit Distance is defined as the minimum number of operations required to convert one string into the other. The allowable operations are:
1. Delete a character
2. Replace a character with another one
3. Insert a character
Input:
String 'S' of length 'N'.
String 'T' of length 'M'.
Output:
Prints the minimum "Edit Distance" between the strings.
Example:
Input:
S = "horse"
T = "ros"
Output:
3
Explanation:
The edit distance between "horse" and "ros" is 3. The operations could be:
1. Replace 'h' with 'r' -> "rorse"
2. Remove 'r' -> "rose"
3. Remove 'e' -> "ros"
Constraints:
0 <= N <= 10^3
0 <= M <= 10^3
- Time Limit: 1 second
Note:
Strings do not contain spaces, and you don't need to print anything as it has been handled. Just implement the required function.
The task is to find the minimum number of operations required to convert one string into another using delete, replace, and insert operations.
Use dynamic programming to solve the problem efficiently.
C...read more
Top TCS SDE-2 interview questions & answers
Popular interview questions of SDE-2
Reviews
Interviews
Salaries
Users/Month