• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
February 22, 2024 |310 Views
Word Break Problem in Dynamic Programming
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Strings but also build up problem-solving skills.

In this problem, we are given a string A and a dictionary of n words B, to find out if A can be segmented into a space-separated sequence of dictionary words. Return 1 if it is possible to break A into a sequence of dictionary words, else return 0.

Note: From the dictionary B each word can be taken any number of times and in any order.

Example :

Input:
n = 6
B = { "i", "like", "sam", "sung", "samsung", "mobile"}
A = "ilike"
Output:
1

Explanation:
The string can be segmented as "i like".

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/word-break1352/1

Article Link: https://www.geeksforgeeks.org/word-break-problem-dp-32/

Read More