text with no spaces and a vocabulary vocab of distinct words. Cut out some non-overlapping pieces of the text so that every piece is a word from the vocabulary. The same word may be used any number of times.
Letters that end up in no piece are stray. Return the smallest possible number of stray letters.text="sunxflower", vocab=["sun", "flow", "flower", "er"] → 1
Take sun and flower (or flow and er), and only the x is left over.
text="catalog", vocab=["cat", "log", "tal"] → 1
cat and tal overlap, and pieces may not share letters. The best choice is cat + log, leaving a single a.
text="qq", vocab=["q", "qqq"] → 0
text) ≤ 50vocab) ≤ 50vocab[i]) ≤ 50text and the vocabulary words consist of lowercase English lettersvocab are distincttext="sunxflower", vocab=["sun", "flow", "flower", "er"]
1
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.