Problems > Edit Distance

Edit Distance

Difficulty: 1700 3000 ms 128 MB

strings dp

Print the minimum number of single-character insertions, deletions and substitutions turning A into B (Levenshtein distance).

Input: two lines: string A, then string B.

Output: the edit distance.

Constraints:

  • 1 ≤ |A|, |B| ≤ 1000
  • lowercase letters

Sample Tests

Input 1
kitten
sitting
Output 1
3
Input 2
abc
abc
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.