Word Break

Medium

Word Break Problem

Problem Statement

Given a string

s
and a set of non-empty words
wordDict
, determine if
s
can be segmented into a sequence of words in
wordDict
.

Rules and Constraints

  • The string
    s
    is composed solely of lowercase English letters.
  • The input string
    s
    may or may not contain spaces between words.
  • The
    wordDict
    set contains unique words composed solely of lowercase English letters.
  • It is guaranteed that all characters of
    s
    and all words in
    wordDict
    are valid English letters.
  • The words in
    wordDict
    may be of varying lengths.
  • Each word in
    wordDict
    corresponds to a valid English word.
  • The
    wordDict
    set is not empty, and it does not contain the empty string.
  • The function should return
    true
    if
    s
    can be segmented into a sequence of words in
    wordDict
    , and
    false
    otherwise.

Output Requirements

  • Return a boolean value (
    true
    or
    false
    ) indicating whether
    s
    can be segmented into a sequence of words in
    wordDict
    .

Example

Input: {"input_data":[1,2,3]} Output: [1,2,3]

CompaniesGoogleMetaAmazon
JavaScript

Login to write code

Solve problems, verify your skills, and earn XP.