Word Search
Try to solve the Word Search problem.
Statement
Given an 2D grid of characters and word
as a string, we need to determine if the word can be constructed from letters of sequentially adjacent cells. The cells are considered sequentially adjacent when they are neighbors to each other either horizontally or vertically. The function should return TRUE if the word can be constructed and FALSE otherwise.
Constraints:
m
board.length
n
board[i].length
, wherei
m
-
m
,n
-
word.length
board
andword
consist of only lowercase or uppercase English letters.- The search is not case-sensitive.
Examples
Understand the problem
Let’s take a moment to make sure you've correctly understood the problem. The quiz below helps you check if you're solving the correct problem:
Word Search
Can we find the word in the given grid?
[['K', 'I', 'C', 'D', 'L', 'J', 'M', 'R']
['V', 'M', 'S', 'P', 'C', 'F', 'A', 'G']
['C', 'A', 'G', 'D', 'J', 'O', 'L', 'O']
['Q', 'Z', 'N', 'T', 'F', 'X', 'C', 'T']
['R', 'L', 'A', 'N', 'I', 'R', 'G', 'D']
['J', 'A', 'W', 'Y', 'M', 'O', 'U', 'A']
['Z', 'A', 'P', 'D', 'R', 'C', 'S', 'D']
['Y', 'V', 'A', 'F', 'P', 'L', 'Z', 'T']]
Yes
No
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground.
function wordSearch(grid, word){// Replace this placeholder return statement with your codereturn false}export {wordSearch}