Trains the technique from
LeetCode 1048Longest String ChainThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Labels are given as words, each a string of lowercase letters.
One label grows into another when inserting a single letter somewhere into the first, without reordering anything else, gives the second exactly.
A chain is a run of labels from the list where each grows into the next. Return the greatest number of labels a chain can hold. A single label is a chain of one.
Example 1
The chain "bd", "abd", "abcd", "abdz" does not work, since "abcd" does not grow into "abdz". The longest chain is "bd", "abd", "abcd", holding three labels.
Example 2
The two labels are the same length, so neither grows into the other and a chain holds one.
Example 3
Each label grows into the next by adding a letter at the end, so all five form one chain.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def longest_str_chain(words: list[str]) -> int:public int longestStrChain(String[] words)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.