LeetCode 472, Hard. Topics: Array, String, Dynamic Programming, Depth-First Search, Trie. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 14 parametrized pytest cases, and a playground notebook:
Problem
Given an array of strings words (without duplicates), return all the concatenated words in the given list of words.
A concatenated word is defined as a string that is comprised entirely of at least two shorter words (not necessarily distinct) in the given array.
Examples
Constraints
1 <= words.length <= 10^4
1 <= words[i].length <= 30
words[i] consists of only lowercase English letters.
- All the strings of
words are unique.
1 <= sum(words[i].length) <= 10^5
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026