Find dictionary words on a board
Return sorted distinct nonempty dictionary words formed by moving horizontally or vertically on a rectangular character board. A cell cannot repeat within one word. Empty board returns [].
trie = {'a': {'b': {'': 'ab'}}}
node = trie['a']['b']
print(node[''])Reason about the state
Build a trie to share dictionary prefixes, then backtrack from each cell while tracking visited positions. Finding a word does not stop longer words with the same prefix. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return sorted distinct nonempty dictionary words formed by moving horizontally or vertically on a rectangular character board. A cell cannot repeat within one word. Empty board returns [].
The explanation opens here once every check passes.