Boggle Game
Master this topic with zero to advance depth.
Boggle Game
Find the maximum number of words you can find in a Boggle board such that no two words overlap (i.e., they don't share any cell).
Visual Representation
Board: ["abc", "def", "ghi"]
Words: ["abc", "defi", "gh"]
Possible Selections:
1. {"abc", "def"} -> 2 words
2. {"abc"} -> 1 word
Result: 2Examples
Input: board = [["a","b","c"],["d","e","f"],["g","h","i"]], words = ["abc","def","gh"]
Output: 2
Approach 1
Level I: Brute Force DFS
Intuition
For each word in the dictionary, perform a standard DFS on the board to see if it exists. Keep track of used cells and try all combinations of non-overlapping words. Very slow but simple.
⏱ O(W * M * N * 4^L)💾 O(M * N)
Approach 2
Level III: Trie + Backtracking (Max Independent Sets)
Intuition
This is a variant of Word Search II. First, find all occurrences of all dictionary words on the board (Word Search II style). Then, treat this as a problem of finding the maximum number of disjoint sets (words) using backtracking. Each word is a set of cell coordinates.
⏱ O(Exp) due to backtracking for disjoint sets.💾 O(N*L)
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.