Mid From PDF Coding C# Coding Interview

Word Break Problem?

bool WordBreak(string s, HashSet<string> wordDict)

{
bool[] dp = new bool[s.Length + 1];
dp[0] = true;
for (int i = 1; i <= s.Length; i++)
{
for (int j = 0; j < i; j++)
{
if (dp[j] && wordDict.Contains(s.Substring(j, i - j)))
{
dp[i] = true;

break;

}
}
}
return dp[s.Length];
}

Explanation:

DP to check if substring can be segmented using dictionary words.

Follow on:

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details