Medium
Array
Hash Table
String
DP
Trie
2707. Extra Characters in a String
You are given a 0-indexed string s
and a dictionary of words dictionary
. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary
. There may be some extra characters in s
which are not present in any of the substrings.
Return the minimum number of extra characters left over if you break up s
optimally.
Example 1:
Example 2:
Constraints:
s.length
<= 50dictionary.length
<= 50dictionary[i].length
<= 50dictionary[i]
and s
consists of only lowercase English lettersdictionary
contains distinct words