Word Search

Given a 2D board of letters and a word, determine if the word exists in the grid by tracing adjacent cells (up/down/left/right) without reuse. Use DFS backtracking.

Input Format

2D list of chars and target word string.

Output Format

Boolean.

Constraints

  • board size ≤ 200x200; word length ≤ 1000.

Examples

Example 1:

Input:

board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]
word = "ABCCED"

Output:

true

Example 2:

Input:

board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]
word = "SEE"

Output:

true

Example 3:

Input:

board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]
word = "ABCB"

Output:

false
Loading...
Word Search - Matrix DSA Problem