← 返回 snowflake 的题目列表Word Search II
类型:qbank
Given a 2-D grid of characters board and a list of strings words, return all words that are present in the grid.
Word Search II
Given a 2-D grid of characters board and a list of strings words, return all words that are present in the grid.
SWE
trie
backtracking
dfs
grid
hard
Frequency
Single report
Last asked
2025-12-03
Stage
phone-screen · onsite-coding
Word Search II
Problem Overview
You are given a 2-D grid of characters called board and a list of strings called words. Your task is to find and return a list of all the words from the input list that actually appear in the grid.
Movement Rules
To find a word, you must trace a path through the grid by connecting letters.
You can move to neighboring cells horizontally (left or right) or vertically (up or down).
Important: You cannot use the exact same cell more than once to form a single word.
Sample Scenarios
Scenario 1:
Input:
board = [
["a","b","c","d"],
["s","a","a","t"],
["a","c","k","e"],
["a","c","d","n"]
]
words = ["bat","cat","back","backend","stack"]
Output:
["cat","back","backend"]
Scenario 2:
Input:
board = [
["x","o"],
["x","o"]
]
words = ["xoxo"]
Output:
[]
Input Limits
Grid Size: The board is small. The height and width are between 1 and 12.
Grid Content: The board only contains lowercase English letters.
Word List Size: The list can be large (up to 30,000 words).
Word Length: The words are short (between 1 and 10 characters).
Character Type: Words only contain lowercase English letters.
Uniqueness: There are no duplicate words in the list.