Skip to contentKEEP THE CRAFTTHE SANCTUARY

Word Search II

Find every dictionary word on a letter board by walking the board and a trie together.

The problem

Implement Solution.findWords(board, words). board is a grid of lowercase letters and words is a list of words. You can form a word by starting at any cell and moving up, down, left or right to the next letter, without using the same cell twice in that word. Return every word from words that can be formed, each word once, in any order. The board has 1 to 12 rows and 1 to 12 columns. There are up to 30,000 words, and each word has 1 to 10 letters.

Starter code

class Solution:
    def findWords(self, board, words):
        pass

Public examples

  1. board = [["o", "a", "a", "n"], ["e", "t", "a", "e"], ["i", "h", "k", "r"], ["i", "f", "l", "v"]], words = ["oath", "pea", "eat", "rain"]gives["oath", "eat"]
  2. board = [["d", "o", "g"]], words = ["do", "dog", "dot"]gives["do", "dog"]
  3. board = [["q", "a", "b"]], words = ["ab", "ba"]gives["ab", "ba"]

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.