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
manuver: 2019-09-28 13:26:37

nothing to worry just declare 2001x2001 global matrix if you are going to use this approach

BTW Good Question

riyaganiga: 2019-08-15 21:36:37

Even though the input descriptions says that there are 10 test cases. Reading the number of test cases is mandatory. Else, WA !!

Sergey: 2019-05-28 21:23:16

All input lines could have "\r\n" sequence at the end, not just '\n' character, be careful with hand-written input and with library-implemented readliners.

gaurav1614: 2019-04-25 03:37:21

""Declare size of dp matrix as 3000X3000 . I declared it as 2003X2003 and it costs me 3 wrong answers . It sucks !!! "" is misleading.i got an AC @abhi_698

abhi_698: 2019-04-21 13:00:20

Declare size of dp matrix as 3000X3000 . I declared it as 2003X2003 and it costs me 3 wrong answers . It sucks !!!

spojwithsaurav: 2019-03-01 19:18:30

AC in one go!!
nice problem

rajat__: 2018-12-16 16:42:41

GOT TLE in top-down????But not in bottom up

double_0_seven: 2018-10-25 00:38:20

AC in one go..!!!

jamesx_: 2018-10-20 16:29:11

Gave TLE when using python 3.5, got accepted using Java. Beware.

Last edit: 2018-10-20 16:29:31
aryan12: 2018-08-30 12:12:24

A nice problem of dynamic programming. For beginners it is a good one. Just remember to declare all the arrays , strings globally , else you will get a runtime error. Costed me a WA.


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