Dynamic programming · 15 / 15 Exercise Hard

Segment with a dictionary

Objective

Given a string without spaces and a set of words, can the string be split into a sequence of words from the set (each may be repeated)? can[i] says whether the prefix of length i can be segmented.

Instructions

  • The first line is the string and the second the dictionary words, separated by spaces.
  • Show Can be segmented or Cannot be segmented.
Input
leetcode
leet code
Output
Can be segmented

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise