TheRealSamuel/LeetCodeProblem
0564
1{2 "id": 2884,3 "name": "length_of_the_longest_valid_substring",4 "difficulty": "Hard",5 "link": "https://leetcode.com/problems/length-of-the-longest-valid-substring/",6 "date": "1688860800000",7 "task_description": "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:** 4 **Explanation:** There are 11 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. It can be shown that all other substrings contain either \"aaa\" or \"cb\" as a substring. ``` **Example 2:** ``` **Input:** word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"] **Output:** 4 **Explanation:** 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. It can be shown that all other substrings contain either \"de\", \"le\", or \"e\" as a substring. ``` **Constraints:** `1 <= word.length <= 105` `word` consists only of lowercase English letters. `1 <= forbidden.length <= 105` `1 <= forbidden[i].length <= 10` `forbidden[i]` consists only of lowercase English letters.",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]",12 "output": "4 "13 },14 {15 "label": "Example 2",16 "input": "word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]",17 "output": "4 "18 }19 ],20 "private_test_cases": [],21 "haskell_template": "longestValidSubstring :: String -> [String] -> Int\nlongestValidSubstring word forbidden ",22 "ocaml_template": "let longestValidSubstring (word: string) (forbidden: string list) : int = ",23 "scala_template": "def longestValidSubstring(word: String,forbidden: List[String]): Int = { \n \n}",24 "java_template": "public static int longestValidSubstring(String word, List<String> forbidden) {\n\n}",25 "python_template": "class Solution(object):\n def longestValidSubstring(self, word, forbidden):\n \"\"\"\n :type word: str\n :type forbidden: List[str]\n :rtype: int\n \"\"\"\n "26}