words of lowercase English words. Word B *grows* from word A if inserting exactly one letter anywhere in A, without reordering the other letters, gives B. For example, cat grows into coat, but tac does not.
A *growth chain* is a sequence of words from the list where each word grows from the one before it. A single word on its own is a chain of length 1.
Return the length of the longest growth chain you can build from the list.words=["to", "t", "tor", "stor", "story", "top"] → 5
t → to → tor → stor → story: each step inserts exactly one letter. The branch to → top is shorter.
words=["ab", "bca"] → 1
bca cannot be made from ab by one insertion without swapping a and b, so the best chain is a single word.
words=["k", "ok", "kok", "oko"] → 3
k → ok → kok (or ok → oko) gives three words.
words) ≤ 1000words[i]) ≤ 30words=["to", "t", "tor", "stor", "story", "top"]
5
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.