Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.
Return all such possible sentences.
For example, given
s = "snakesandladder",
dict = ["snake", "snakes", "and", "sand", "ladder"].
A solution is ["snakes and ladder",
"snake sand ladder"].
The first line contains an integer T, denoting the number of test cases.
Every test case has 3 lines.
The first line contains an integer N, number of words in the dictionary.
The second line contains N strings denoting the words of the dictionary.
The third line contains a string s.
For each test case, print all possible strings in one line. Each string is enclosed in (). See Example.
If no string possible print "Empty" (without quotes).
1<=Length of each word in dictionary <=15
1<=Length of s<=1000
Note: Make sure the strings are sorted in your result.
lr m lrm hcdar wk
(hcdar lr m)(hcdar lrm)
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.