Find Every Dictionary Word Hidden in a Letter Grid
Last updated: November 29, 2026
Quick Overview
Given a grid of letters and a list of dictionary words, return every word that can be traced through horizontally or vertically adjacent cells without reusing a cell within one word.
Microsoft
November 29, 20260
0
0 solved
Given a grid of letters and a list of dictionary words, return every word that can be traced through horizontally or vertically adjacent cells without reusing a cell within one word.
A classic Microsoft onsite problem with a casual-games flavor (think a word game in the Microsoft Casual Games collection), used to see whether a candidate combines a trie with grid DFS instead of searching the grid once per word. Strong candidates also prune the trie as words are found.
What the Interviewer Expects
- Build a trie of the dictionary so all words are searched in one DFS
- Backtrack by marking cells visited in place and restoring them
- Store the full word at the terminal node to avoid rebuilding strings
- Prune exhausted trie branches so later searches get faster
- Avoid duplicate results when a word can be traced twice
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How does the worst case change if the dictionary has 500,000 words?
- How would you allow diagonal moves?
- How would you parallelize across many boards on a server?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
The board is an m x n grid of lowercase letters (as a list of lists so it can be marked in place). Words are distinct. Moves are up, down, left, right. A cell cannot be used twice in the same word. Re...
High-Level Design
Searching the board separately for every word repeats the same prefixes over and over. Instead, insert all words into a trie and run one DFS from every cell, walking the trie in parallel with the grid...