pyassistant

Longest String Chain (one-character insert)

Given a list of lowercase strings, find the length of the longest possible chain of words where each word in the chain is formed by inserting exactly one character into the previous word (at any position). Each word in the chain must appear in the given list. Return an integer representing the maximum chain length. Example: ['a', 'ab', 'abc'] has a longest chain length 3.

Example:

Input:
['a', '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.