Word Search II
Hard Tries
board is a grid of m rows and n columns, each cell holding a lowercase letter. words is a list of different words, also of lowercase letters.
A word is on the board when a walk spells it: start on a cell holding its first letter, then step each time to a cell above, below, left or right of the one you are on, holding the next letter. A walk never comes back to a cell it has used, though different words may use the same cells.
Return every word of words that is on the board, in any order. Each appears once in the answer, however many walks spell it.
Example 1
cat runs along the top row, ring goes down from r and then along the bottom row, and red along the middle row. tree has no r next to its t, and tat would need the one t twice.
Example 2
tone goes round the board. toe would need a diagonal step from o to e, and toot needs a second t and o.
Example 3
Constraints
1 ≤ m, n ≤ 12board[i][j]is a lowercase English letter1 ≤ words.length ≤ 2 × 10⁴1 ≤ words[i].length ≤ 10, andwords[i]is lowercase English letters- The words in
wordsare all different
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundMore Tries
- Word BreakAI round · Medium
- Implement Trie (Prefix Tree)AI round · Medium
- Design Add and Search Words Data StructureAI round · Medium
- Longest Common PrefixEasy
- Top K Frequent WordsMedium