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?
- Delete one letter from one of strings
- Insert one letter into one of strings
- Replace one of letters from one of strings with another letter
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.
For each test case, one line, minimum number of operations.
Input: 1 FOOD MONEY Output: 4
nothing to worry just declare 2001x2001 global matrix if you are going to use this approach
Even though the input descriptions says that there are 10 test cases. Reading the number of test cases is mandatory. Else, WA !!
All input lines could have "\r\n" sequence at the end, not just '\n' character, be careful with hand-written input and with library-implemented readliners.
""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
Declare size of dp matrix as 3000X3000 . I declared it as 2003X2003 and it costs me 3 wrong answers . It sucks !!!
AC in one go!!
GOT TLE in top-down????But not in bottom up
AC in one go..!!!
Gave TLE when using python 3.5, got accepted using Java. Beware.Last edit: 2018-10-20 16:29:31
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.