Word Search II
Problem Statement
You get a board of letters (a grid) and a list of words. Find every word from the list that you can spell on the board.
To spell a word, start on any cell whose letter is the word's first letter. Each next letter must be on a cell directly above, below, left or right of the previous cell. A cell can be used at most once in the same word.
Return all the words you can spell, in any order.
board: a grid of lowercase letters. words: a list of different lowercase words.
A list of every word from words that can be spelled on the board. Any order is fine.
oath goes o → a → t → h. eat goes e → a → t. pea needs a p, and the board has none. rain needs an a next to the r, and there is none.
abcb needs two bs. The board has only one b, and a cell cannot be used twice in one word.
- • The board has between 1 and 12 rows and between 1 and 12 columns.
- • Every board cell holds a lowercase English letter.
- • The list has between 1 and 3 · 10^4 words.
- • Each word has between 1 and 10 letters, all lowercase.
- • All the words in the list are different from each other.
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Word Search from every cell, repeated for every word; O(W · m·n · 4^L)
Put every word in a trie; walk the board with trie nodes; stop when the letter is not a child; cut used-up branches
Word Search answers one question: is this word on the board? Ask it once for every word in the list and keep the ones that pass. To check one word, try each cell as the first letter, step to neighbours that match the next letter, and mark a cell as used while it is on the current path. When the walk backs up, the cell is free again.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Trie translate into production architectures and low-level memory mechanics.