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.

  1. Use a boolean dp array of size n+1. dp[0] = true.
  2. For each index i:
    • Check all previous split points j.
    • If dp[j] is true AND s.substring(j, i) is in the dictionary, set dp[i] = true.
  3. Print true or false.

01EXAMPLE 1

Inputs="leetcode", dict=["leet", "code"]
Outputtrue

Explanation: Valid split.

Constraints

  • Dictionary can contain any number of words.
AlgorithmsDynamic ProgrammingStrings
JavaScript
Loading...
1 Hidden

Input Arguments

s"leetcode"
wordDict["leet","code"]

Expected Output

true

Click RUN to test your solution