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

imkiller: 2018-03-25 16:37:47

Just a simple editDistance problem .
solve using dp.
No constraints problem.
BestOfLuckForOthers.

erfanesm: 2018-02-20 07:31:38

this problem can't be solve in this way :
cout<< max(s.size(),t.size) - LCS.size();
S = abba , T = bcba;
LCS = bba => LCS.size() = 2
so our output will be 4-3 = "1"
it takes us 2_operations :
1. Delete "C" => to string S
2. Insert "A" => to string T

Last edit: 2018-02-20 07:33:07
bradyawn: 2018-01-24 22:23:33

AC in one go!!! = Why I hate SPOJ community
People should shut up about AC in one go and do actually challenging problems

nveenjain: 2018-01-16 10:59:53

Pass strings through reference, costed TLE :(

asifk1997: 2018-01-14 05:25:55

standard dp problem
AC in one go!!!

Last edit: 2018-01-14 06:54:23

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