levenshtein

Problem Description

The Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other. It is named after the Soviet mathematician Vladimir Levenshtein, who considered this distance in 1965.

Given lowercase strings A and B, find the Levenshtein distance between A and B.

Input

The first line of input will contain a string A

The second line of input will contain a string B

Output

The output should contain one integer representing the Levenshtein distance.

Limits

Let N and M be length of A and B respectively.

Subtask 1 (27%): 1 ≤ N, M ≤ 10

Subtask 2 (73%): 1 ≤ N, M ≤ 3 000

Subtask 3 (0%): Sample Testcases.

Sample Input 1

abc
bcd

Sample Output 1

2

Explanation

Delete 'a', insert 'd'.

Sample Input 2

saturday
sunday

Sample Output 2

3

Explanation

Replace 'n' with 'r', insert ‘t’, insert ‘a’.

Submitting .cpp to 'levenshtein'


You're not logged in! Click here to login

Time Limit: 1 Seconds
Memory Limit: 256MB
Your best score: 0
Source: Classic problem

Subtask Score
1 27
2 73
3 0