Question DSA-DP-0062
HardWhat is the output of this code?
def word_break(s, words):
ok = [True] + [False] * len(s)
for i in range(1, len(s) + 1):
ok[i] = any(ok[j] and s[j:i] in words for j in range(i))
return ok[-1]
W = {"apple", "pen", "applepen", "pine", "pineapple"}
print(word_break("pineapplepenapple", W), word_break("catsandog", {"cats", "dog", "sand", "and", "cat"}))
- A.
True True
- B.
False True
- C.
Sign up free to see the answer and a step-by-step explanation.