Solve the finding if a word is consisted of two words in a dictionary problem in O(n^2).