Word Break
Medium Tries
s is a string of lowercase letters, and wordDict is a list of different words, also of lowercase letters.
To cut `s` into words is to split it into pieces, in order and with nothing left over, so that every piece is a word of wordDict. A word may be used any number of times, or not at all.
Return true if s can be cut into words, and false if it cannot.
Example 1
Cut it as book, shelf and book again: every piece is a word, and a word may be used twice. Starting with books instead leaves helfbook, which no word begins, but one way is enough.
Example 2
Example 3
Constraints
1 ≤ s.length ≤ 4001 ≤ wordDict.length ≤ 10001 ≤ wordDict[i].length ≤ 20sandwordDict[i]are lowercase English letters- The words in
wordDictare all different
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundWatch the explanation
More Tries
- Implement Trie (Prefix Tree)AI round · Medium
- Word Search IIAI round · Hard
- Design Add and Search Words Data StructureAI round · Medium
- Longest Common PrefixEasy
- Top K Frequent WordsMedium