Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given two strings **s** and **t. **Return the minimum number of operations required to convert **s **to **t**.

The possible operations are permitted:

- Insert a character at any position of the string.
- Remove any character from the string.
- Replace any character from the string with any other character.

**Example 1:**

**Input: **
s = "geek", t = "gesek"
**Output:** 1
**Explanation: **One operation is required
inserting 's' between two 'e's of str1.

**Example 2:**

**Input : **
s = "gfg", t = "gfg"
**Output: **
0
**Explanation: **Both strings are same.

**Your Task:**

You don't need to read or print anything. Your task is to complete the function **editDistance() **which takes strings s and t as input parameters and returns the minimum number of operation to convert the string **s** to string** ****t**.

**Expected Time Complexity: **O(|s|*|t|)

**Expected Space Complexity: **O(|s|*|t|)

**Constraints:**

1 ≤ Length of both strings ≤ 100

Both the strings are in lowercase.

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Edit Distance

...