Notice Period

Dictionary Splits

medium

A legacy logging system stripped all the spaces out of its messages. You have the smashed-together string text and the system's known vocabulary vocab.

Return True if text can be split into a sequence of one or more vocabulary words (words may repeat), else False.

Example 1
in text = "applepie", vocab = ["apple", "pie"]
out True
"apple" + "pie".
Example 2
in text = "catsandog", vocab = ["cats", "dog", "sand", "and", "cat"]
out False
Every split strands at least one unmatched letter.
Constraints
  • · 1 <= len(text) <= 300
  • · 1 <= len(vocab) <= 50
  • · 1 <= len(vocab[i]) <= 20
  • · lowercase letters only
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.