Find Words on a Board

Given a character board and a dictionary, return every word that can be formed by moving horizontally or vertically between adjacent cells. Pattern focus: Word Search with Trie (Multi-Word DFS). This variant emphasizes clean trie traversal with deterministic output ordering.

Input Format

board = character grid, words = dictionary words

Output Format

all matched words in lexicographic order

Constraints

  • 1 <= rows * cols <= 10^4
  • 1 <= words.length <= 3 * 10^4
  • Board and words contain only lowercase English letters.

Examples

Example 1:

Input:

board = [["s","e","a"],["t","r","e"],["n","o","w"]]
words = ["sea","sear","row","stone"]

Output:

["row","sea"]

Explanation:

Only the words that can be traced with adjacent moves are returned.

Example 2:

Input:

board = [["a"]]
words = ["b"]

Output:

[]

Explanation:

A non-matching single-cell grid returns no result.

Example 3:

Input:

board = [["c","a","t"],["a","r","e"],["d","o","g"]]
words = ["cat","car","dog","cog"]

Output:

["car","cat","dog"]

Explanation:

Multiple valid words may be discovered from the same board.

Loading...
Find Words on a Board - Trie DSA Problem