The Concatenated Words interview question asks you to find all strings in a given list that are "concatenated words." A concatenated word is defined as a string that can be entirely formed by joining at least two other shorter words from the same list.
Companies like Salesforce, Amazon, and Apple use the Dynamic Programming interview pattern to test your string decomposition skills. It’s a variation of the "Word Break" problem but applied to an entire set. It evaluates if you can optimize the search by sorting words by length or using a Trie/HashSet to speed up the sub-word lookups.
The most common approach is DFS with Memoization or Word Break DP.
dp[i] is true if the prefix of length i can be formed by words in the set.Words: ["cat", "cats", "dog", "catsdogcats"]
Mention that you can use a Trie to further optimize the prefix searching. This is particularly useful if the words share many common prefixes.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Remove Sub-Folders from the Filesystem | Medium | Solve | |
| Longest Word With All Prefixes | Medium | Solve | |
| Extra Characters in a String | Medium | Solve | |
| Number of Ways to Form a Target String Given a Dictionary | Hard | Solve | |
| Delete Columns to Make Sorted III | Hard | Solve |