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
Chetan sharma: 2013-01-17 10:54:12

I ma getting NZEC in python. I have made all possible changes that could be made to avoid NZEC. Could any please suggest. I don't know if I can paste my code here.

ron2794: 2012-12-27 12:53:15

yup.. seg fault problem is solved by taking the array as global and static int.
but i didn't get it, why this happened, why the problem solved this way ?

Gunjit : 2012-12-05 20:20:30


use global array ...

Last edit: 2012-12-05 20:22:49
Paul Draper: 2012-11-19 08:41:54

Simón Murillo Gómez and others, I depended on string length no more than 2000 and got AC

Ashok: 2012-10-20 05:17:48

@:P thanks a lot.

hot: 2012-09-28 05:55:40

what will be the answer if any of or both strings are empty...?

Simón Murillo Gómez: 2012-07-29 17:14:49

The size is more than 2000.
4 WA before change it to 3000

i_am_what_i_am: 2012-07-12 07:44:46

Do we need to convert the string into uppercase character by our own or is it by default assumed to be in uppercase character

Surya: 2012-07-02 13:56:29

@I am back, Nikhar : SIGSEGV is because of the 2D array size if you have used. In case of 2000 length, seg fault. Use static int array with fixed size if required!

npsabari: 2012-07-01 18:44:26

wth?? SEG fault again again.. though its working fine in my comp!
@nikhar : did you figure what went wrong?

Atlast!! learnt a new way to solve!!

Last edit: 2012-07-01 21:15:59

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