LeetCode 943, Hard. Topics: Array, String, Dynamic Programming, Bit Manipulation, Bitmask, Hamiltonian Path. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 57 parametrized pytest cases, and a playground notebook:
Problem
Given an array of strings words, return the smallest string that contains each string in words as a substring. If there are multiple valid strings of the smallest length, return any of them.
You may assume that no string in words is a substring of another string in words.
Examples
Constraints
1 <= words.length <= 12
1 <= words[i].length <= 20
words[i] consists of lowercase English letters.
- All the strings of
words are unique.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026