This is an interview question. Suppose you have a string text and a dictionary (a set of strings). How do you break down text into substri
text
dictionary
There is a very thorough writeup for the solution to this problem in this blog post.
The basic idea is just to memoize the function you've written and you'll have an O(n^2) time, O(n) space algorithm.