Find Shortest Superstring

Find the shortest string that contains every given word as a contiguous substring. Precompute overlap lengths between all word pairs, then use DP over bitmasks (traveling-salesman style) to find the optimal concatenation order.

Examples
Input: ["alex","loves","leetcode"]
Output: "leetcodelovesalex"
Hints

Find Shortest Superstring

Find the shortest string that contains every given word as a contiguous substring. Precompute overlap lengths between all word pairs, then use DP over bitmasks (traveling-salesman style) to find the optimal concatenation order.