Find Two-Word Compound Words
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: Review a compound-word coding prompt that finds words formed by concatenating exactly two other words in the same list. The question focuses on split-point checks, hash sets, deterministic output, trie follow-ups, and avoiding self-use edge cases.
Constraints
- Words are unique lowercase strings.
- Return one valid pair if several exist.
Examples
Input: (['cat','dog','catdog','cats','dogcat'])
Expected Output: [('catdog','cat','dog'),('dogcat','dog','cat')]
Input: (['a','aa','aaa'])
Expected Output: [('aa','a','a'),('aaa','a','aa')]
Input: (['blue','berry','blueberry','black'])
Expected Output: [('blueberry','blue','berry')]
Input: (['x','y','z'])
Expected Output: []
Input: (['ab','a','b','abc','bc'])
Expected Output: [('ab','a','b'),('abc','a','bc')]
Input: ([])
Expected Output: []
Input: (['home','work','homework','workhome'])
Expected Output: [('homework','home','work'),('workhome','work','home')]
Input: (['aa','a','aaa','aaaa'])
Expected Output: [('aa','a','a'),('aaa','a','aa'),('aaaa','a','aaa')]
Hints
- Try each split point.
- A trie can avoid repeated substring hashing for larger inputs.