Find Every Brand Name Hidden in a Warehouse Letter-Tile Grid
Last updated: November 29, 2026
Quick Overview
Given an m x n grid of letters and a list of brand names, return every name that can be traced through adjacent cells (up, down, left, right) without reusing a cell within one name.
Amazon
November 29, 20260
0
0 solved
Given an m x n grid of letters and a list of brand names, return every name that can be traced through adjacent cells (up, down, left, right) without reusing a cell within one name.
A hard onsite question in Amazon's style that combines a trie with grid backtracking. The interviewer expects you to move from running one search per word to a single DFS guided by a trie, and to add pruning so large dictionaries stay fast.
What the Interviewer Expects
- Identifies the per-word search as too slow for large word lists
- Builds a trie and runs one DFS from each cell
- Marks and restores visited cells in place
- Stores the word at terminal nodes and removes it after finding to avoid duplicates
- Prunes empty trie branches as words are found
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 complexity change if diagonal moves are allowed?
- How would you parallelize this across a very large grid?
- How would you return the cell path for each found word?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Grid up to 12 x 12, up to names of length up to 10. Moves are 4-directional; a cell is used at most once per name. Return each found name once (order not important, sorted here for test...
High-Level Design
Running a separate DFS per name repeats work: names that share a prefix walk the same cells again. Insert all names into a trie and launch one DFS from every cell, descending only while the current tr...