← DiffPush

Word search in grid

DiffPush Tier Recursion · Try Out All Combos O(M * N * 4^L) — every cell can seed a walk of L letters · O(L) recursion depth

Tracing the Courier's Call Sign Across the Switchboard

A dispatch switchboard lays out letters in a grid, and a courier's call sign must be traced as a path through adjacent cells — stepping up, down, left, or right without reusing a cell. An operator starts on any cell matching the first letter, marks it taken, and probes onward for each following letter, un-marking on the way back so other routes stay available.

Input: A grid board of characters and the target string word.

Output: true when some adjacent-cell path spells word, false otherwise.

Constraints

Examples

Example 1

Input: {"board":[["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]],"word":"ABCCED"}
Output: true
The path A→B→C→C→E→D snakes through the left half of the grid.

Example 2

Input: {"board":[["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]],"word":"ABCB"}
Output: false
Reaching B after C would require reusing the starting cell, which the no-revisit rule forbids.

Solve this in your browser →

Also on LeetCode ↗