Word Breaking

ARRAY
STRING

Problem

Given a target string text and an array of strings dictionary, determine whether text can be segmented into a space-separated sequence of one or more dictionary words in dictionary.

Examples:

canBreakString("applepie", ['apple', 'pie', 'cat', 'comb', 'bat']) // true /* The input string 'applepie' can be segmented into words 'apple' and 'pie', both of which are present in the given dictionary. */ canBreakString("catcomb", ['apple', 'pie', 'cat', 'comb', 'bat']) // true canBreakString("applestraw", ['apple', 'pie', 'cat', 'comb', 'bat']) // false
Loading...