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
bazinga012: 2017-05-12 23:23:09

Taking string input using cin.getline gives WA used scanf with %s and it worked. What is the reason??

bazinga012: 2017-05-12 23:11:15

Getting WA. Can anyone give edge cases. Tried everything got accept on two other portals with same algo.

rknguyen: 2017-05-02 05:08:43

:lol: i solved MBLAST first :v

Last edit: 2017-05-02 05:18:56
ramesh_961: 2017-04-27 14:26:48

Then what is the output for "AGGTAB" and "GXTXAYB" ??
and Is LCS concept useful here??

akki: 2017-04-11 19:59:02

@abbi_18 At any given point you just require only n-elements, hence you don't need to store n*n elements. If you think in this direction you'll be able to reduce space complexity from O(n^2) to O(n).

ashu121: 2017-03-30 20:59:52

AC in one go
use bottom up technique for three operations:
1. insert
2. delete
3. substitute

sunny: 2017-03-19 08:25:52

Nice problem :-). Learned an algorithm.

rishab05: 2017-03-16 03:57:49

It's giving successful results in my IDE and even in ideone. But giving Segmentation fault while submitting.
I am using Memoization approach!!

vijayrit: 2017-03-14 16:22:42

got correct output on ideone but getting segmentation erroe on spoj........
please help

da_201501181: 2017-03-04 11:05:09

Nice Question..!! Learned a lot..!!


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