PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • hard
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Find Two-Word Compound Words

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

Given a list of unique lowercase words, return every word that can be formed by concatenating exactly two other words from the same list. For each compound word, also return one valid pair of component words. A word may not use itself as one of its components. Function signature: ```python def two_word_compounds(words: list[str]) -> list[tuple[str, str, str]]: pass ``` Constraints: - All words contain lowercase English letters. - The output may be returned in any order unless the interviewer asks for sorting. - If multiple pairs form the same word, returning any one valid pair is acceptable. - Do not use a word as its own component. Examples: ```text words = ['cat', 'dog', 'catdog', 'cats', 'dogcat'] Output may include [('catdog', 'cat', 'dog'), ('dogcat', 'dog', 'cat')] ``` ```text words = ['a', 'aa', 'aaa'] Output may include [('aa', 'a', 'a'), ('aaa', 'a', 'aa')] ```

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.

Return every word that can be formed by concatenating exactly two words from the same list. For each compound, return one valid pair.

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

  1. Try each split point.
  2. A trie can avoid repeated substring hashing for larger inputs.
Last updated: Jul 8, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)
  • Circular Drone Hub Delivery Route - Amazon (hard)
  • Leaf Domain Cumulative Scores - Amazon (medium)
  • Kth Largest Perfect Binary Subtree - Amazon (medium)
  • Find Conflicting Events - Amazon (medium)