Word Break - aloalgo

Word Break

Medium

You are given a string s and a dictionary of words dictionary.

Your task is to determine if the string s can be segmented into a space-separated sequence of one or more words, where each word in the sequence is found in your dictionary.

You may assume that:

  • Words from dictionary may be reused multiple times in the segmentation.

Return true if s can be segmented, false otherwise.

Example 1

Inputs
s = "helloworld"
dictionary = ["hello", "world"]
Output
True
Explanation:

"helloworld" can be segmented as "hello world" using the words from the dictionary.

Example 2

Inputs
s = "penpineappleapplepen"
dictionary = ["apple", "pen", "pineapple"]
Output
True
Explanation:

"penpineappleapplepen" can be segmented as "pen pineapple apple pen".

Example 3

Inputs
s = "helloearth"
dictionary = ["hello", "art", "ear", "heart"]
Output
False
Explanation:

"helloearth" cannot be fully segmented using the provided dictionary words.

Loading...
Inputs
s = "helloworld"
dictionary = ["hello", "world"]
Output
True

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!