For this Question: 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.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) <= 105Print the concatenated words ;
Note:- If there are no concatenating words then print -1Sample 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, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
unordered_set<string>s;
vector<string>res;
bool dfs(int start,int end,string word)
{
if(start==end)
{
return true;
}
for(int i=start+1;i<=end;i++)
{
string subword=word.substr(start,i-start);
if(s.find(subword)!=s.end())
{
if(dfs(i,end,word))
{
return true;
}
}
}
return false;
}
vector<string>
findAllConcatenatedWords(vector<string>& words) {
for(int i=0;i<words.size();i++)
{
s.insert(words[i]);
}
for(int i=0;i<words.size();i++)
{
for(int j=1;j<words[i].length();j++)
{
if(s.find(words[i].substr(0,j))!=s.end())
{
if(dfs(j,words[i].length(),words[i]))
{
res.push_back(words[i]);
break;
}
}
}
}
return res;
}
int main()
{
int l;
cin >> l;
string k;
vector<string> words;
for(int i=0; i < l; i++){
cin >> k;
words.push_back(k);
}
res = findAllConcatenatedWords(words);
if(res.empty()){
cout << -1 ;
return 0;
}
for(auto i = res.begin(); i != res.end(); i++){
cout << *i << " ";
}
cout << "\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?