Word Search
Problem
You are given an m x n grid of letters board and a string word. Decide whether word can be traced in the grid by starting at any cell and moving to an orthogonally adjacent cell for each successive letter. Each cell may be used at most once within a single trace.
- The board has at most 10 rows and 10 columns.
- The word has at most 20 letters.
boardandwordcontain only letters.
Examples
board = [["M","N","O","Q"],["T","R","O","T"],["M","P","Q","Q"]], word = "MNOOQP"→true. Start at(0,0), go right twice, down, down, left.- Same board,
word = "TQQ"→true. Start at(1,3), then(2,3), then(2,2). - Same board,
word = "MNON"→false. The onlyNadjacent to the finalOis the one already used.
Hints
- From any cell that matches
word[0], what do you need to check next, and where? - A path cannot revisit a cell. How do you record "in use" while exploring, and what must you do when the exploration fails?
- DFS from each matching start cell, matching one letter per step; temporarily mark the current cell (e.g. write
'#') and restore it on the way back so other branches can use it.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.