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
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

justcodeit99: 2018-11-01 10:32:36

https://www.youtube.com/watch?v=We3YDTzNXEk

he is the greatest teacher of dp ever!

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.

mindjolt2406: 2018-07-25 18:20:26

Empty strings are to be taken care of too.

castor21: 2018-06-16 08:29:27

ac in 3 gos using dog biscuit


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