Class Solution
java.lang.Object
g2701_2800.s2781_length_of_the_longest_valid_substring.Solution
2781 - Length of the Longest Valid Substring.<p>Hard</p>
<p>You are given a string <code>word</code> and an array of strings <code>forbidden</code>.</p>
<p>A string is called <strong>valid</strong> if none of its substrings are present in <code>forbidden</code>.</p>
<p>Return <em>the length of the <strong>longest valid substring</strong> of the string</em> <code>word</code>.</p>
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string, possibly empty.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> word = “cbaaaabc”, forbidden = [“aaa”,“cb”]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong></p>
<p>There are 9 valid substrings in word: “c”, “b”, “a”, “ba”, “aa”, “bc”, “baa”, “aab”, “ab”, "abc"and “aabc”. The length of the longest valid substring is 4.</p>
<p>It can be shown that all other substrings contain either “aaa” or “cb” as a substring.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> word = “leetcode”, forbidden = [“de”,“le”,“e”]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong></p>
<p>There are 11 valid substrings in word: “l”, “t”, “c”, “o”, “d”, “tc”, “co”, “od”, “tco”, “cod”, and “tcod”. The length of the longest valid substring is 4.</p>
<p>It can be shown that all other substrings contain either “de”, “le”, or “e” as a substring.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= word.length <= 10<sup>5</sup></code></li>
<li><code>word</code> consists only of lowercase English letters.</li>
<li><code>1 <= forbidden.length <= 10<sup>5</sup></code></li>
<li><code>1 <= forbidden[i].length <= 10</code></li>
<li><code>forbidden[i]</code> consists only of lowercase English letters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
longestValidSubstring
-