Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

board =
words =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Search the board with DFS, but prune paths using a trie of the dictionary.

Approach

  1. Build a trie of words. Store the full word at terminal nodes.
  2. For each cell, DFS following trie edges.
  3. Mark visited cells with # during the DFS path.
  4. When a trie node contains a word, add it and null it to avoid duplicates.
  5. Optional pruning: remove leaf trie nodes after use.

Why it works

The trie prevents exploring prefixes that don’t lead to any word, turning exponential exploration into heavily-pruned search.

Code
Loading...
Complexity
Time: O(mn * 4^L) worst-case, typically much less with trie pruning
Space: O(sum(words) + L)
Solution
Updated: 2026-02-23

Idea

Search the board with DFS, but prune paths using a trie of the dictionary.

Approach

  1. Build a trie of words. Store the full word at terminal nodes.
  2. For each cell, DFS following trie edges.
  3. Mark visited cells with # during the DFS path.
  4. When a trie node contains a word, add it and null it to avoid duplicates.
  5. Optional pruning: remove leaf trie nodes after use.

Why it works

The trie prevents exploring prefixes that don’t lead to any word, turning exponential exploration into heavily-pruned search.

Code
Loading...
Complexity
Time: O(mn * 4^L) worst-case, typically much less with trie pruning
Space: O(sum(words) + L)