Imagine you're a treasure hunter with a grid of letters and a list of secret words to find! Your mission is to discover which words are hidden in the grid by connecting adjacent letters.
Given an m x n board of characters and a list of strings words, return all words that can be found on the board. Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring (no diagonal moves allowed). The same letter cell may not be used more than once in a single word.
Example: If your board contains letters arranged in a grid and you're searching for words like "OATH" and "PEA", you need to trace a path through adjacent cells to spell out each word completely.
Input & Output
Visualization
Time & Space Complexity
MΓN cells Γ 4^L paths, where L is max word length. Trie allows early pruning.
Trie storage for K words with average length L, plus recursion stack
Constraints
- m == board.length
- n == board[i].length
- 1 β€ m, n β€ 12
- board[i][j] is a lowercase English letter
- 1 β€ words.length β€ 3 Γ 104
- 1 β€ words[i].length β€ 10
- words[i] consists of lowercase English letters
- All the strings of words are unique