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
4mo

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!
Select
Add answer anonymously...
TCS SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits