EDIST - Edit distance


You are given two strings, A and B. Answer, what is the smallest number of operations you need to
transform A to B?

Operations are:

  1. Delete one letter from one of strings
  2. Insert one letter into one of strings
  3. Replace one of letters from one of strings with another letter

Input

T - number of test cases

For each test case:

  • String A
  • String B

Both strings will contain only uppercase characters and they won't be longer than 2000 characters. 

There will be 10 test cases in data set.

Output

For each test case, one line, minimum number of operations.

Example

Input:
1
FOOD
MONEY

Output:
4

hide comments
Ankit Aggarwal : 2014-07-19 14:22:57

use dynamic memory allocation!!

Rajat (1307086): 2014-07-08 10:32:44

Famous Levenshtein distance problem.
One of best question for dynamic programming intro.Read more of it at
en.m.wikipedia.org/wiki/Levenshtein_distance

excursionist: 2014-07-03 19:16:48

my 100th :D

Atreyee: 2014-06-20 08:25:20

Getting TLE even after doing it by DP :(

Vikas Yadav: 2014-06-10 13:39:56

nice dp prob, AC in 1 go :-)

fallacy: 2014-06-07 16:09:24

TLE :( ?

sanban: 2014-06-05 11:18:37

For
1
ALLAHABAD
YATINDRA
shouldn't the ans be 6??
as we can add an A and then replace the remaining Y,T,I,N,R with A,L,L,H,B...making it six steps

Agam Gupta: 2014-05-21 11:51:59

got AC :)

Last edit: 2014-05-21 12:20:01
Rishav Goyal: 2014-03-30 07:57:57

i bet my sol is correct.!!

mohamad alshboul: 2014-02-07 22:56:15

weak test cases !!
some cases isn't covered ex:
BA
BAA
but nice standard DP problem :)


Added by:Mislav Balunović
Date:2010-02-28
Time limit:15s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Internet