The EndGame : Concatenated Words(Contest)
The EndGame : Concatenated Words easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
The EndGame : Concatenated Words easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement :
Given an array of strings words (without duplicates), return all the concatenated words in the given list of words. A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array. Input The first line contains integer N denoting the length of the array Second- line contains N space-separated strings (words)
Constraints:- 1 <= N <= 15 1 <= words[i]. length <= 20 words[i] consists of only lowercase English letters. 0 <= sum(words[i]. length) <= 105 Output Print the concatenated words ; Note:- If there are no concatenating words then print -1 Example Sample Input:- 8 cat cats catsdogcats dog dogcatsdog hippopotamuses rat ratcatdogcat
Sample Output:- catsdogcats dogcatsdog ratcatdogcat
Explanation : catsdogcats can be concatenated by cats, dog and cats. dogcatsdog can be concatenated by dog, cats and dog. ratcatdogcat can be concatenated by rat, cat, dog and cat.
Sample Input:- 3 cat dog catdog
Sample Output: catdog
link: