Word Search II

Hard
Concept
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Word Search II

Approach

Insert all dictionary words in trie, then DFS the board; prune branches when next character is absent in trie.

Complexity Analysis

Time
O(M * N * 4^L)
Space
O(W * L)

Pattern

Trie + Grid DFS (Pruned)

Why It Works

Trie prunes non-prefix paths early, preventing exponential growth from branches that can never form a valid word.

Updated Feb 2026