Word Search II
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at Word Search II is running a separate DFS for every word. Amazon candidates reported this one in September 2026, and with up to 30000 words on a 12 x 12 board, that approach times out fast. The real pattern is a trie plus backtracking on the grid. You build one prefix tree from all the words, then walk the board once and prune whenever the current path isn't a prefix of anything. If you blank mid-assessment, StealthCoder runs invisibly as a safety net and shows you the structure while you type.
The problem
Given an m x n board of lowercase English letters and an array of distinct lowercase words, return every word that can be formed on the board. A word is formed by starting at any cell and repeatedly moving one cell horizontally or vertically. A board cell may be used at most once while forming one word. Return found words in the same order in which they appear in words. Function findWords(board: char[][], words: String[]) → String[] Examples Example 1 board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]] words = ["oath","pea","eat","rain"] return = ["oath","eat"] The paths o-a-t-h and e-a-t use horizontal or vertical neighbors without reusing a cell. Example 2 board = [["a","b"],["c","d"]] words = ["abcb","abcd","acdb"] return = ["acdb"] acdb follows the path down, right, then up. The other words require a reused cell or a diagonal move. Constraints 1 <= m, n <= 12. 1 <= words.length <= 30000. 1 <= words[i].length <= 10. The board and every word contain only lowercase English letters. All words are distinct.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to flip the search. Insert every word into a trie, then start a DFS from each cell, following the trie as you move up, down, left and right. When you hit a node that marks a word end, record it. Mark the cell visited before recursing and restore it afterward, since a cell can only be used once per word. The hinted binary-search pattern doesn't apply here. Nothing is sorted and there's no monotonic answer. Common pitfalls: searching word by word, adding duplicate results when a word is reachable by several paths, and forgetting that output must follow the original order of words. Fix that by storing the word index at the trie node, or by filtering the original list against a found set at the end. Pruning exhausted trie branches speeds things up a lot. If your recursion goes sideways under pressure, StealthCoder is the hedge on the live OA.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Word Search II cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as word search ii. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Word Search II FAQ
What's the trick in Word Search II?+
Build a trie from all words, then run one backtracking DFS over the board guided by the trie. You abandon a path the moment the current letters aren't a prefix of any word. That shared prefix pruning replaces thousands of separate word searches.
Why does searching word by word fail?+
With up to 30000 words, a full board DFS per word multiplies the work by the word count. A trie lets all words share the same traversal, so each board path is explored once regardless of how many words start with the same letters.
How do I keep results in the original word order?+
Collect found words in a set, then iterate the original words array and keep the ones in the set. You could also store each word's index at its trie end node and sort the indices at the end. Either way avoids duplicates and respects the required order.
Is binary search relevant here?+
No. Nothing is sorted and you're not searching a numeric answer range. The core is trie plus DFS backtracking with a visited marker. Treat the binary-search hint as noise and focus on prefix pruning.
How do I prepare for this in 48 hours?+
Write the trie insert by hand, then code the backtracking with mark and unmark on the visited cell. Run example 2 to confirm no cell reuse and no diagonal moves. Then add pruning of dead trie branches. That covers everything this problem tests.