hard

Word Search II

Given a letter grid and a list of words, return all words from the list that can be formed by paths of adjacent cells without reusing a cell. The list can contain thousands of words.

Constraints
  • 1 ≤ m, n ≤ 12
  • 1 ≤ words.length ≤ 3 · 10^4
  • 1 ≤ word length ≤ 10
  • All words distinct
Examples
in: board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]
out: ["eat","oath"]

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.