1172. Edit Distance (Levenshtein)

EasyDynamic ProgrammingSequence DP

Given two strings a and b, return the minimum number of single-character insertions, deletions, or substitutions to transform a into b. The input is JSON {a, b}.

Input: JSON {a, b}.

Output: Integer — the edit distance.

Examples

Example 1
Input: {"a":"horse","b":"ros"}
Output: 3
Explanation: Three edits.
Example 2
Input: {"a":"intention","b":"execution"}
Output: 5
Explanation: Five edits.
Example 3
Input: {"a":"","b":"abc"}
Output: 3
Explanation: Three insertions.

Constraints

Asked by

SwiggyFlipkartAmazonInfosysBloombergDeloitte
Solve this problem in the editor →