Word Search II
Return the distinct dictionary words that can be traced in a letter board using orthogonally adjacent cells, without reusing a cell within one word. Return words in any order.
Example 1
0,0c
0,1a
1,0t
1,1p
board = [["c","a"],["t","p"]]
words = ["cat","cap","at","ca","cc"]["cap","ca"]Explanation
cap follows (0,0)->(0,1)->(1,1), and ca its first two cells; other words need a diagonal or reuse.
Example 2
0,0a
board = [["a"]]
words = ["a","aa"]["a"]Explanation
One cell spells a but cannot be reused for aa.
Example 3
0,0x
0,1y
board = [["x","y"]]
words = ["z"][]Explanation
No board cell contains z, so no word matches.
Constraints
- 1 <= rows, columns <= 12
- At most 30000 distinct nonempty lowercase words of length <= 10
Function contract
findWordsArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[["c","a"],["t","p"]]["cat","cap","at","ca","cc"]