25 · Tries

#212 Word Search II

Hardsolve on LeetCode ↗

frequently reported atUberAirbnbByteDance / TikTokAmazonMicrosoftGoogle

the problem

In plain words

Given an m×n board of letters and a list of words, return every word that can be formed by a path of horizontally or vertically adjacent cells, using each cell at most once per word.

in board = ["oaan","etae","ihkr","iflv"], words = ["oath","pea","eat","rain"]

out ["eat","oath"]

Any order is accepted.

in board = ["ab","cd"], words = ["abcb"]

out []

The second 'b' would reuse a cell.

  • 1 ≤ m, n ≤ 12
  • 1 ≤ words.length ≤ 3·10⁴
  • 1 ≤ words[i].length ≤ 10
  • Words are unique, lowercase

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #79
      Word Search
      Mediumin Backtracking
    2. #211
    3. #208