pyassistant

Longest String Chain by Single-Character Insertion

Given a list of lowercase strings, find the length of the longest string chain. A string chain is defined as a sequence of words [w1, w2, ..., wk] such that for every i from 1 to k-1, wi+1 is formed by inserting exactly one character anywhere into wi (no rearrangement allowed). Return the length k of the longest possible chain. If the list is empty return 0.

Example:

Input:
['a', 'b', 'ba', 'bca', 'bda', 'bdca']
Output:
4

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.