Word Search
Given an `m x n` grid of characters `board` and a string `word`, return `true` if `word` exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once. **Examples:** ```typescript exist([["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], "ABCCED") // true exist([["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], "SEE") // true exist([["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], "ABCB") // false ```
Solve It in the BrowserPractice Explaining It Out Loud
Optimal Approach
- Time complexity: O(m * n * 3^L)
- Space complexity: O(L)
From each starting cell, DFS branches in 3 directions up to word length L.
Follow-Up Questions Interviewers Ask About Word Search
- How to avoid allocating extra memory for visited tracking?
Temporarily mutate board[r][c] to a sentinel character like '#' and restore it upon backtracking.
Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.