Gamified challenge · DP over prefixes
s is a sentence of lowercase letters with no spaces, and words is the scanner's dictionary. Write wordBreak(s, words) (Python word_break) that returns true if s can be cut into pieces that are all dictionary words, in order, with nothing left over, and false otherwise.
A word may be used any number of times. The empty sentence needs no words, so it is true; dictionary words are never empty.
Example: "starfishbowl" with ["sta", "star", "fish", "starfish", "bowl", "fishbowl"] is true (star fish bowl, or starfish bowl), but "redbluegreed" with ["red", "blue", "green", "bluegreen", "reed"] is false.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google