291. Shortest Superstring (Length)

HardStringString

Given an array of strings words (none being a substring of another), return the length of the shortest string that contains each word as a substring. Words may overlap to save length. Input: a JSON array of strings.

Input: JSON array of strings.

Output: Integer — length of the shortest superstring.

Examples

Example 1
Input: ["alex","loves","leetcode"]
Output: 17
Explanation: No overlaps possible; total length 17.
Example 2
Input: ["catg","ctaagt","gcta","ttca","atgcatc"]
Output: 23
Explanation: Optimal overlapping arrangement.
Example 3
Input: ["abc"]
Output: 3
Explanation: Single word.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →