Length of the Longest Valid Substring
You are given a string word and an array of strings forbidden.
A string is called valid if none of its substrings are present in forbidden.
Return the length of the longest valid substring of the string word.
A substring is a contiguous sequence of characters in a string, possibly empty.
Example 1
Input
word = "cbaaaabc", forbidden = ["aaa","cb"]Output
4There are 11 valid substrings in
word, and the longest valid substring is "aabc" with length 4.Example 2
Input
word = "leetcode", forbidden = ["de","le","e"]Output
4There are 11 valid substrings in
word, and the longest valid substring is "tcod" with length 4.Constraints
- 1 <= word.length <= 10^5
- word consists only of lowercase English letters.
- 1 <= forbidden.length <= 10^5
- 1 <= forbidden[i].length <= 10
- forbidden[i] consists only of lowercase English letters.