The Semantic Split
HardAcc. 68.4%
+70 XP 35
Segmented Feasibility
A string s can be broken if there exists a split point j such that s[0...j] is breakable AND s[j...i] is in the dictionary.
The Assignment
Your function receives s and wordDict.
- Use a boolean
dparray of sizen+1.dp[0] = true. - For each index
i:- Check all previous split points
j. - If
dp[j]is true ANDs.substring(j, i)is in the dictionary, setdp[i] = true.
- Check all previous split points
- Print true or false.
01EXAMPLE 1
Input
s="leetcode", dict=["leet", "code"]Output
trueExplanation: Valid split.
Constraints
- Dictionary can contain any number of words.
AlgorithmsDynamic ProgrammingStrings
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
s"leetcode"
wordDict["leet","code"]
Expected Output
true
Click RUN to test your solution