Introduction
It is a hard level algorithm called interleave string. I have no idea how to learn a hard level algorithm, I just plan to spend 30 minutes time on this algorithm first. Now it is 12:46 PM, I will end the study at 1:16 PM.
Brainstorming ideas
Brute force solution - using linear scan from left to right
Check length to see if longest one is the sum of two small ones.
Count how many chars from a - z and see if the sum of each char equals to the sum of interleave string by characters.
Try to think about go from two ends of the interleave string, and find chars from the two strings to match. There is a recurrence formula.
Now it is 1:12 PM. Let me read one of solutions.
One more thinking,
"a"
"a"
"aa"
"ab"
"a"
think about short string first char position in the longer string, there are how many possible position:
length + 1, check prefix and compare to interleave string's prefix to see if there is a match.
Solution
I just cannot believe that the dynamic programming method is very similar to Deletion distance.
No comments:
Post a Comment