Practice/Amazon/Leetcode 212. Word Search II
CodingMust
You are given a 2D character grid (board) and a list of target words. Your task is to find all words from the list that can be constructed by tracing a path through adjacent cells in the grid.
A valid path must follow these rules:
Return all words from the input list that can be found in the grid. The order of the returned words does not matter.
m == board.length (number of rows)n == board[i].length (number of columns)1 <= m, n <= 12board[i][j] is a lowercase English letter1 <= words.length <= 30,0001 <= words[i].length <= 10words[i] consists of lowercase English letterswords array are uniqueExample 1:
` 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"]
Explanation:
Example 2:
` Input: board = [["a","b"], ["c","d"]] words = ["ab","ba","cd"]
Output: ["ab","ba","cd"]
Explanation: All three words can be found by connecting adjacent cells. `
Example 3:
` Input: board = [["a"]] words = ["a","aa"]
Output: ["a"]
Explanation: Only the single-letter word "a" can be found. `