Concatenated Words

Given a list of distinct lowercase words, return every word that can be formed by concatenating at least two shorter words taken from the same list.

Rules that follow from the definition:

  • A word may not be a component of itself. The whole word must never be the only piece.
  • A shorter word may be reused as often as needed inside one assembly.
  • A component has to be strictly shorter than the word being built.
  • Return the matching words in the order they appear in the input list.
  • Return an empty list when no word matches.
Examples
Input: ["ab","cd"]
Output: []
Hints

Concatenated Words

Given a list of distinct lowercase words, return every word that can be formed by concatenating at least two shorter words taken from the same list.