Asked inTCS,SDE-2

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.

AnswerBot
1d

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

Help your peers!
Add answer anonymously...
TCS SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter