# Word Break with Trie Pruning (Practice 5068): Rehearsal
Interviewers use this pattern to test whether you can state the invariant before coding. Here is a compact rehearsal note.
## Approach
Bottom-up DP where reachable[i] marks a valid split; a word set plus max word length keeps the inner loop short.
```python
def word_break(s,words):
ws=set(words);L=max(map(len,ws));ok=[True]+[False]*len(s)
for i in range(1,len(s)+1):
for j in range(max(0,i-L),i):
if ok[j] and s[j:i] in ws: ok[i]=True;break
return ok[-1]
```
## Complexity
Linear in the dominant input size for the scan; heap/tree variants add a log factor.
## Interview pitfalls
State the invariant out loud, name the complexity, then code. Skipping the invariant is the usual fail mode.
## Practicing out loud
Narrate the approach, complexity and one edge case in under a minute. Disclosure: I work on Linkjob AI, a real-time interview assistant. If you want live practice help, see real-time interview help.
Published with deed.pageReport abuse