💡
Exercise 151

Word Search II 30 XP Hard

LeetCode Ctrl+Enter Run Ctrl+S Save

Given a board and a list of words, find all words that can be formed on the board. Combines Trie + Backtracking — the ultimate combo.

Build a Trie from all words. DFS from each board cell, following Trie paths. When we reach is_end, we found a word. Prune branches with no Trie matches.

💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!

📋 Instructions
Find all words from the list that exist in the board. Print count found.
Build Trie from words. For each cell, DFS while following Trie. When is_end found, add word to result.
🧪 Test Cases
Input
len(findWords(board, words))
Expected
2
Test case 1
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.