
Asked in Dunzo
Word Break II Problem Statement
Given a non-empty string 'S' containing no spaces and a dictionary of non-empty strings, generate and return all possible sentences by adding spaces in the string 'S', such that each word in a sentence exists in the given dictionary.
Note:
The same word in the dictionary can be used multiple times to form sentences. Assume there are no duplicate words in the dictionary.
Input:
The first line contains an integer 'T' denoting the number of test cases.
Then the 'T' test cases follow.
The first line of each test case contains an integer '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'.
Output:
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.
Note:
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.
Constraints:
- 1 <= T <= 10
- 1 <= K <= 100
- 1 <= |word| <= 16
- 1 <= |S| <= 13
- Time Limit: 1 sec

AnswerBot
4mo
Given a string and a dictionary, generate all possible sentences by adding spaces between words from the dictionary.
Use backtracking to generate all possible sentences by recursively adding words from...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Dunzo
Q. Asteroid Collision Problem Description Given an array/list ASTEROIDS representin...read more
Q. Valid Parentheses Problem Statement Given a string 'STR' consisting solely of th...read more
Q. Trie Data Structure Implementation Design and implement a Trie (Prefix Tree) whi...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Dunzo Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

