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
@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).
AC in one go
Nice problem :-). Learned an algorithm.
It's giving successful results in my IDE and even in ideone. But giving Segmentation fault while submitting.
got correct output on ideone but getting segmentation erroe on spoj........
Nice Question..!! Learned a lot..!!
I don't understand. Does insertion and deletion take place only at the end or wherever in between?
Python (both 2.7 and 3.4) seems to bump into TLE, both for the O(N*2) and O(N) memory versions. There's no point in even trying it. There seems to be 6 successful Python 2.7 submissions from 2015, but maybe they tightened the running time restriction since then.
Top down solution gets TLE??
Awesome qs, done it in O(n*n) space complexity, can anybody please suggest a place where i can learn it solve it in O(n) space complexity?