coding•DSA & Problem Solving•Graphs & Backtracking
Word Search
Problem Statement
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.
### Constraints
- `m == board.length`
- `n = board[i].length`
- `1 <= m, n <= 6`
- `1 <= word.length <= 15`
- `board` and `word` consist of only lowercase and uppercase English letters.
### Input Format
- Line 1: `m n word` (two integers and a string).
- Next `m` lines: `n` space-separated characters.
### Output Format
Print `true` or `false`.
Sample Cases
Example 1Sample Case
Input: 3 4 ABCCED
A B C E
S F C S
A D E E
Output: true
Example 2Sample Case
Input: 3 4 SEE
A B C E
S F C S
A D E E
Output: true
Example 3Sample Case
Input: 1 1 A
A
Output: true
Example 4Sample Case
Input: 1 2 CD
A B
Output: false
Constraints
Runtime Limit: 2000 ms per test batch
Memory Limit: 256 MB
Standard I/O stream reading
Official submissions are evaluated against hidden test cases on the server to verify time & memory complexity.