pyassistant

Length of Shortest Common Supersequence for Multiple Strings

Given a list of strings strs, find the length of the shortest string S such that every string in strs is a subsequence of S. You may append characters to S in any order; characters cannot be reordered within each input string (subsequence relation). Return the minimum possible length of S. You may assume strings contain only lowercase English letters. This is a hard problem for multiple strings (generalized shortest common supersequence). Inputs will be moderate-sized (for example, up to ~10 strings of length up to ~20) so an exponential-in-number-of-strings dynamic search is acceptable. Implement an algorithm that returns the minimal length.

Example:

Input:
(['ab', 'bc'],)
Output:
3

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.