DSA · Backtracking · #08
Word Search
Module 10 · difficulty 3/5·⏱ 30:00starts on first keystroke
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 in a single path.
Examples
board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"→trueboard = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"→trueboard = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"→false— B at (0,1) cannot be reused
Constraints
- · m == board.length
- · n == board[i].length
- · 1 <= m, n <= 6
- · 1 <= word.length <= 15
- · board and word consist of only uppercase and lowercase English letters.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.