Longest String Chain
Question (LC.1048)
Given a list of words, find the length of the longest word chain.
A word chain is defined as word_1, word_2, ..., word_n and word_i+1 has exactly one more letter than word_i.
Examples
I: words = ["a","b","ba","bca","bda","bdca"]
O: 4 (a -> ba -> bca -> bdca)
I: words = ["xbc","pcxbcf","xb","cxbc","pcxbc"]
O: 5
I: words = ["abcd","dbqca"]
O: 1Approach
Drawing out the nodes in this search graph is going to be very helpful. Each word can be a node in the graph and the edges are the chains between words.

Graph Search
TLE 78 / 79 tests passed
Memoized Search
Now the runtime is bounded by the size of the input
Last updated