Medium · Dynamic Programming

Longest String Chain

Given an array of words, return the length of the longest word chain, in which each word is the previous word with exactly one letter inserted anywhere, the other letters keeping their order. A single word is a chain of length 1.

Examples

Example 1

["a","b","ba","bca","bda","bdca"]

Output: chain = 4

Example 2

["xbc","pcxbcf","xb","cxbc","pcxbc"]

Output: chain = 5

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Dynamic Programming problems