PROBLEM 39 OF 75

Word Search II

Return all dictionary words present in a board without reusing cells.

PATTERNTries & prefix searchA path is a prefix; an end marker is a word.
SPOT THE SIGNAL

Why does this pattern fit?

FRAME · 1 OF 4

Restate the exact job

Return all dictionary words present in a board without reusing cells.

WHY THIS FITS

A trie shares prefix work across many words and prunes impossible paths.

COMPLEXITY

O(mn·4^L) worst-case · O(dictionary characters) space

COMMON FAILURE

Running a separate board search for every word repeats prefixes.

THE REASONING, IN ONE PLACE

How to solve Word Search II

The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.

What the question asks

Return all dictionary words present in a board without reusing cells.

Why Tries & prefix search fits

A trie shares prefix work across many words and prunes impossible paths.

State to maintain

Board position, trie node, visited mark, and found-word marker.

Transition

Advance the trie with the cell, emit terminal words once, explore neighbors, and prune dead trie branches.

Time and space

O(mn·4^L) worst-case · O(dictionary characters) space

Counterexample to the tempting mistake

Running a separate board search for every word repeats prefixes.

Prove it again tomorrow

Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.

Open blank recall ↗