Problem of the day
The same word in the dictionary can be used multiple times to make sentences.
Assume that the dictionary does not contain duplicate words.
The first line contains an integer ‘T’ denoting the number of test cases.
Then the 'T' test cases follow.
The first line contains an integer value ‘K’ which denotes the size of the dictionary.
The second line contains ‘K’ non-empty, space separated strings denoting the words of the dictionary.
The third line contains a non-empty string ‘S’.
For each test case, print each possible sentence after adding spaces, in different lines.
The output of each test case is printed in a separate line.
1. You do not need to print anything, it has already been taken care of. Just implement the given function.
2. The order in which the output sentences are returned does not matter.
1 <= T <= 10
1 <= K <= 100
1 <= | word | <= 16
1 <= | S | <= 13
where |word| is the length of each word in the dictionary and |S| is the length of the string S.
Time Limit: 1 sec
1
6
god is now no where here
godisnowherenowhere
god is no where no where
god is no where now here
god is now here no where
god is now here now here
One way to make sentences is to take “god” and append a space, then take “is” and append space, take “now” from the dictionary and take “here” as well.
Similarly, for other sentences also, we can add space to get other possible sentences. Note that we can reuse dictionary words as “no” and “now” are used two times in the same sentence.
1
4
god is no here
godisnowhere
No output to be printed
We can not make any sentence because after making “god is no” we will be stuck with “where”. There is no way to break “where” further such that we can get any word from the dictionary.