MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / is_breakable

Function is_breakable

dynamic_programming/word_break.py:84–103  ·  view source on GitHub ↗

>>> string = 'a' >>> is_breakable(1) True

(index: int)

Source from the content-addressed store, hash-verified

82 # Dynamic programming method
83 @functools.cache
84 def is_breakable(index: int) -> bool:
85 """
86 >>> string = 'a'
87 >>> is_breakable(1)
88 True
89 """
90 if index == len_string:
91 return True
92
93 trie_node: Any = trie
94 for i in range(index, len_string):
95 trie_node = trie_node.get(string[i], None)
96
97 if trie_node is None:
98 return False
99
100 if trie_node.get(word_keeper_key, False) and is_breakable(i + 1):
101 return True
102
103 return False
104
105 return is_breakable(0)
106

Callers 1

word_breakFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected