ExamAdda Logo

Word Search

Easy

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 cell may not be used more than once.

Example 1

Input

3 4
A B C E
S F C S
A D E E
ABCCED

Output

true

Explanation

The word ABCCED can be formed by moving through adjacent cells horizontally and vertically without using any cell more than once.

Example 2

Input

3 4
A B C E
S F C S
A D E E
SEE

Output

true

Explanation

The word SEE exists in the grid using adjacent cells.

Constraints

1 <= m
n <= 6
1 <= m * n <= 36
1 <= word.length <= 15
board[i][j] is an English letter.
word contains only English letters.
The same cell cannot be used more than once.

Hints:

Hint 1

Try starting the search from every cell whose character matches the first character of word.

Hint 2

Use DFS/backtracking to explore the four possible directions.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 21, 2026

Last updated

Aug 21, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output