Word Break Problem
📖 Scenario: Imagine you have a long string of letters without spaces, and you want to check if it can be split into valid words from a dictionary. This is like trying to read a message where spaces are missing and figuring out if it makes sense.
🎯 Goal: You will build a program that checks if a given string can be segmented into a sequence of dictionary words. This helps understand how to use arrays and loops to solve problems step-by-step.
📋 What You'll Learn
Create a string variable called
input with the exact value "applepenapple".Create an array of strings called
dictionary with these exact words: "apple", "pen".Create an integer variable called
dictSize and set it to 2.Create an integer array called
dp with size strlen(input) + 1.Write a loop to fill
dp with zeros and set dp[0] to 1.Use nested loops to check all substrings of
input and update dp to mark valid breaks.Print
"true" if the whole string can be segmented, otherwise print "false".💡 Why This Matters
🌍 Real World
This problem helps in text processing tasks like spell checking, auto-correct, and natural language processing where words need to be identified in a continuous text.
💼 Career
Understanding this problem shows your ability to use arrays, loops, and string functions in C, which are essential skills for software development and technical interviews.
Progress0 / 4 steps