Determines if the input string can be segmented into a sequence of valid dictionary words using backtracking. Parameters: input_string (str): The input string to segment. word_dict (set[str]): The set of valid words. Returns: bool: True if the string can be segmented i
(input_string: str, word_dict: set[str])
| 46 | |
| 47 | |
| 48 | def word_break(input_string: str, word_dict: set[str]) -> bool: |
| 49 | """ |
| 50 | Determines if the input string can be segmented into a sequence of |
| 51 | valid dictionary words using backtracking. |
| 52 | |
| 53 | Parameters: |
| 54 | input_string (str): The input string to segment. |
| 55 | word_dict (set[str]): The set of valid words. |
| 56 | |
| 57 | Returns: |
| 58 | bool: True if the string can be segmented into valid words, otherwise False. |
| 59 | |
| 60 | Example: |
| 61 | >>> word_break("leetcode", {"leet", "code"}) |
| 62 | True |
| 63 | |
| 64 | >>> word_break("applepenapple", {"apple", "pen"}) |
| 65 | True |
| 66 | |
| 67 | >>> word_break("catsandog", {"cats", "dog", "sand", "and", "cat"}) |
| 68 | False |
| 69 | |
| 70 | >>> word_break("applepenapple", {}) |
| 71 | False |
| 72 | """ |
| 73 | |
| 74 | return backtrack(input_string, word_dict, 0) |
nothing calls this directly
no test coverage detected