{"id":"eef8cf89-a921-4f43-815b-a05a3f3f0965","name":"Word Break - I","description":"1. You are given n space separated strings, which represents a dictionary of words.\r\n2. You are given another string which represents a sentence.\r\n3. You have to print all possible sentences from the string, such that words of the sentence are \r\n present in dictionary.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without \r\n changing signature. The judge can't force you but intends you to teach a concept.","inputFormat":"A number n \r\nn strings representing words\r\na string representing a sentence","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= number of words &lt;= 10\r\n1 &lt;= length of each word &lt;= 15\r\n1 &lt;= length of sentence &lt;= 1000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tHashSet<String> dict = new HashSet<>();\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tdict.add(scn.next());\r\n\t\t}\r\n\t\tString sentence = scn.next();\r\n\t\twordBreak(sentence,\"\", dict);\r\n\t}\r\n\r\n\tpublic static void wordBreak(String str, String ans, HashSet<String> dict){\r\n\t\t// write your code here\r\n\t}\r\n\t\t\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"11\r\ni like pep coding pepper eating mango man go in pepcoding\r\nilikepeppereatingmangoinpepcoding","sampleOutput":"i like pepper eating man go in pep coding \r\ni like pepper eating man go in pepcoding \r\ni like pepper eating mango in pep coding \r\ni like pepper eating mango in pepcoding \r\n","questionVideo":"https://www.youtube.com/embed/LmHWIsBQBU4?end=95","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"1a283edb-9ea2-4f9e-b463-0e565d5e3c13","name":"Word Break - I","slug":"word-break-i","type":1}],"next":{"id":"6bb4b4c6-1bea-4275-bc64-111fe5d16e14","name":"Word break-1 MCQ","type":0,"slug":"word-break-1-mcq"},"prev":{"id":"7a4b9f01-5eef-401b-ac55-59891259a185","name":"Pattern Matching MCQ","type":0,"slug":"pattern-matching-mcq"}}}

Word Break - I

1. You are given n space separated strings, which represents a dictionary of words. 2. You are given another string which represents a sentence. 3. You have to print all possible sentences from the string, such that words of the sentence are present in dictionary. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

{"id":"eef8cf89-a921-4f43-815b-a05a3f3f0965","name":"Word Break - I","description":"1. You are given n space separated strings, which represents a dictionary of words.\r\n2. You are given another string which represents a sentence.\r\n3. You have to print all possible sentences from the string, such that words of the sentence are \r\n present in dictionary.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without \r\n changing signature. The judge can't force you but intends you to teach a concept.","inputFormat":"A number n \r\nn strings representing words\r\na string representing a sentence","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= number of words &lt;= 10\r\n1 &lt;= length of each word &lt;= 15\r\n1 &lt;= length of sentence &lt;= 1000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tHashSet<String> dict = new HashSet<>();\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tdict.add(scn.next());\r\n\t\t}\r\n\t\tString sentence = scn.next();\r\n\t\twordBreak(sentence,\"\", dict);\r\n\t}\r\n\r\n\tpublic static void wordBreak(String str, String ans, HashSet<String> dict){\r\n\t\t// write your code here\r\n\t}\r\n\t\t\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"11\r\ni like pep coding pepper eating mango man go in pepcoding\r\nilikepeppereatingmangoinpepcoding","sampleOutput":"i like pepper eating man go in pep coding \r\ni like pepper eating man go in pepcoding \r\ni like pepper eating mango in pep coding \r\ni like pepper eating mango in pepcoding \r\n","questionVideo":"https://www.youtube.com/embed/LmHWIsBQBU4?end=95","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"1a283edb-9ea2-4f9e-b463-0e565d5e3c13","name":"Word Break - I","slug":"word-break-i","type":1}],"next":{"id":"6bb4b4c6-1bea-4275-bc64-111fe5d16e14","name":"Word break-1 MCQ","type":0,"slug":"word-break-1-mcq"},"prev":{"id":"7a4b9f01-5eef-401b-ac55-59891259a185","name":"Pattern Matching MCQ","type":0,"slug":"pattern-matching-mcq"}}}
plane

Editor


Loading...

Word Break - I

easy

1. You are given n space separated strings, which represents a dictionary of words. 2. You are given another string which represents a sentence. 3. You have to print all possible sentences from the string, such that words of the sentence are present in dictionary. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

Constraints

1 <= number of words <= 10 1 <= length of each word <= 15 1 <= length of sentence <= 1000

Format

Input

A number n n strings representing words a string representing a sentence

Output

Check the sample ouput and question video.

Example

Sample Input

11 i like pep coding pepper eating mango man go in pepcoding ilikepeppereatingmangoinpepcoding

Sample Output

i like pepper eating man go in pep coding i like pepper eating man go in pepcoding i like pepper eating mango in pep coding i like pepper eating mango in pepcoding

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode