Skip to content
Decoder

Word Search

Medium

Problem

Given a grid of letters board (a list of rows, each a list of single characters) and a word, return whether the word can be traced in the grid. You trace by starting on any cell and moving one step up, down, left or right for each next letter. A cell cannot be used twice in the same word.

Example 1

board = [["A","B","C","E"],

Example 2

         ["S","F","C","S"],

Example 3

         ["A","D","E","E"]]

Example 4

Input
word = "ABCCED"
Output
True

Example 5

Input
word = "SEE"
Output
True

Example 6

Input
word = "ABCB"
Output
False
Why
would need to reuse the B

Constraints

  • 1 <= rows, cols <= 6
  • 1 <= word.length <= 15
  • board and word contain only upper and lower case English letters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.