270. Concatenated Words (Count)

HardStringString

Given a list of words (without duplicates), return the number of concatenated words — words that are formed entirely by concatenating at least two shorter words from the same list. Input: a JSON array of strings.

Input: JSON array of strings.

Output: Integer — count of concatenated words.

Examples

Example 1
Input: ["cat","cats","catsdogcats","dog","dogcatsdog","hippopotamuses","rat","ratcatdogcat"]
Output: 3
Explanation: catsdogcats, dogcatsdog, ratcatdogcat.
Example 2
Input: ["cat","dog","catdog"]
Output: 1
Explanation: 'catdog'.
Example 3
Input: ["a","b","c"]
Output: 0
Explanation: None are concatenations.

Constraints

Asked by

Amazon
Solve this problem in the editor →