Back to Practice
#0286
Word Search
MediumDSA28 min20 XP
Problem
Given a board and word, return True if the word can be built from horizontally or vertically adjacent cells. A cell cannot be reused in the same word path.
Why This Matters
Word Search combines grid DFS with backtracking state cleanup, a frequent interview combination.
Function Signature
def exist(board, word):
Examples
Example 1
Inputboard = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
OutputTrue
The path A -> B -> C -> C -> E -> D exists through adjacent cells.
Constraints
- Return the exact requested value.
- Handle edge cases cleanly.
- Use the intended DSA pattern when brute force would scale poorly.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Word exists
InputABCCED
ExpectedTrue
A valid adjacent path exists.
Cannot reuse cell
InputABCB
ExpectedFalse
The path would need to reuse the B cell.
Hidden Test Categories
single-cell boardword longer than cellssame letter repeated