Find Compound Product Names Made Entirely of Other Names
Last updated: November 29, 2026
Quick Overview
Given a list of distinct words, return every word that can be written as a concatenation of at least two shorter words from the same list.
0
0
0 solved
Given a list of distinct words, return every word that can be written as a concatenation of at least two shorter words from the same list.
Appears in Google onsites framed around a product catalog or a Search query vocabulary where compound terms like "photobook" should be split. The interviewer checks a trie-driven DP over each word and the rule that a word may not use itself.
What the Interviewer Expects
- Process words in increasing length so only shorter words are in the trie
- Run a DP over each word using trie walks to find valid next cut points
- Require at least two parts
- Skip empty strings
- Analyze cost in terms of word length squared
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the actual split for each compound?
- How would you handle a dictionary of 10 million words?
- What if words may be reused across compounds with a cost per part?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: words, distinct lowercase strings. Output: all words that equal a concatenation of two or more words from the list (repeats of the same shorter word are allowed). Order of output does not mat...
High-Level Design
Sort words by length. A word can only be composed of strictly shorter words, so when we test a word, the trie should hold exactly the words seen before it. For each word w, run a reachability DP: `o...