778. Edit Distance (Recursive + Memoization)

MediumRecursionRecursion

Given two strings s1 and s2, return the MINIMUM number of operations required to convert s1 into s2. The allowed operations on either string are:
1. Insert a character.
2. Delete a character.
3. Replace a character.
Implement the solution with recursion + memoization.

Input is two quoted strings separated by a comma.

Input: Two strings in quotes separated by ', '.

Output: Return an integer — the edit (Levenshtein) distance.

Examples

Example 1
Input: "horse", "ros"
Output: 3
Explanation: horse -> rorse (replace) -> rose (delete) -> ros (delete).
Example 2
Input: "intention", "execution"
Output: 5
Explanation: Five operations needed.
Example 3
Input: "abc", "abc"
Output: 0
Explanation: Already identical.

Constraints

Asked by

SwiggyFlipkartAmazonInfosysBloombergDeloitte
Solve this problem in the editor →