Word Search II
Given an m x n board of characters and a list of words, return all words from the list that can be formed by a path of horizontally or vertically adjacent cells, where each cell may be used at most once per word.
Open official problem prompt ↗Find which dictionary words appear as adjacency-connected paths in the grid, doing it efficiently for a large word list.
A word-search puzzle where, instead of hunting each word separately, you carry one master index (the trie) so a single sweep of the grid checks every word's prefix at once.
- Input
- board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]
- Output
- ["oath","eat"]
- Why
- "oath" and "eat" each trace a connected path of adjacent cells; "pea" and "rain" cannot be traced.
m == board.lengthn == board[i].length1 <= m, n <= 12board[i][j] is a lowercase English letter1 <= words.length <= 3 * 10^41 <= words[i].length <= 10All words[i] are unique