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
Kaustubh Mallik: 2015-01-22 06:29:02

Even 2D array solution is accepted. :D

Takanori MAEHARA: 2015-01-18 16:59:55

@simple
My 0.02s solution is a bit-parallel algorithm. see http://www.sis.uta.fi/~hh56766/pubs/psc02.pdf

Infinity: 2014-10-18 08:39:53

my time 1.21
best time 0.1 and 0.5
I WOULD like to know your approach.

Last edit: 2014-10-18 08:40:46
mandu_ism: 2014-10-05 23:52:48

Made a mistake in calculating min!!

I need sleep :(

mayank: 2014-09-29 10:48:32

There is no need for 1D array, in C++ at least. :)

Trương Ngọc Duy: 2014-09-24 05:12:50

Edit size MAX 3000 ... NOT 2000!

Trương Ngọc Duy: 2014-09-24 05:07:37

How to using 1D ??? help me !

bhumik: 2014-09-20 16:50:56

What is answer for
1
SATURDAY
SUNDAY

My solution which got AC gave 7 as output but ans should be 3 as we can delete 'A' and 'T' from SATURDAY and then convert 'R' to 'N'.

deCodeIt: 2014-09-13 07:11:37

gave SIGSEV error with 2D array... as memory exceeded.. But worked awesome with 1D.... :) (y)

mitz: 2014-08-17 13:53:40

good one!!!
use 1D array in c

Last edit: 2014-08-17 13:54:40

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