{"id":"01841431-3d9d-4322-88cf-1030e0422c66","name":"Word Break 2","description":"1. You are given n space-separated strings, which represents a dictionary of words.\r\n2. You are given another string that represents a sentence.\r\n3. You have to determine if this sentence can be segmented into a space-separated sequence of one or more dictionary words.","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 boolean solution(String sentence, HashSet<String> dictionary) {\r\n\t\t//write your code here\r\n\r\n\t\treturn false;\r\n\t}\r\n\t\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> dictionary = new HashSet<String>();\r\n\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\tdictionary.add(scn.next());\r\n\t\t}\r\n\t\tString sentence = scn.next();\r\n\t\tSystem.out.println(solution(sentence, dictionary));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"2\r\npep coding\r\npepcoding","sampleOutput":"true\r\n","questionVideo":"","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"39b6079d-b13c-41ed-91d5-598e591c555e","name":"Word Break 2","slug":"word-break-2","type":1}],"next":{"id":"0ed79e40-48be-4fe9-88a0-ac7a3d2bf3e8","name":"Word Wrap","type":1,"slug":"word-wrap"},"prev":{"id":"b19d90df-115a-4462-8e9c-102151f9b471","name":"Arithmetic Slices 2","type":1,"slug":"arithmetic-slices-2"}}}

Word Break 2

1. You are given n space-separated strings, which represents a dictionary of words. 2. You are given another string that represents a sentence. 3. You have to determine if this sentence can be segmented into a space-separated sequence of one or more dictionary words.

{"id":"01841431-3d9d-4322-88cf-1030e0422c66","name":"Word Break 2","description":"1. You are given n space-separated strings, which represents a dictionary of words.\r\n2. You are given another string that represents a sentence.\r\n3. You have to determine if this sentence can be segmented into a space-separated sequence of one or more dictionary words.","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 boolean solution(String sentence, HashSet<String> dictionary) {\r\n\t\t//write your code here\r\n\r\n\t\treturn false;\r\n\t}\r\n\t\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> dictionary = new HashSet<String>();\r\n\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\tdictionary.add(scn.next());\r\n\t\t}\r\n\t\tString sentence = scn.next();\r\n\t\tSystem.out.println(solution(sentence, dictionary));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"2\r\npep coding\r\npepcoding","sampleOutput":"true\r\n","questionVideo":"","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"39b6079d-b13c-41ed-91d5-598e591c555e","name":"Word Break 2","slug":"word-break-2","type":1}],"next":{"id":"0ed79e40-48be-4fe9-88a0-ac7a3d2bf3e8","name":"Word Wrap","type":1,"slug":"word-wrap"},"prev":{"id":"b19d90df-115a-4462-8e9c-102151f9b471","name":"Arithmetic Slices 2","type":1,"slug":"arithmetic-slices-2"}}}
plane

Editor


Loading...

Word Break 2

medium

1. You are given n space-separated strings, which represents a dictionary of words. 2. You are given another string that represents a sentence. 3. You have to determine if this sentence can be segmented into a space-separated sequence of one or more dictionary words.

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

2 pep coding pepcoding

Sample Output

true

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode