Word Search in a Letter Grid

medium
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 16. Everything before it counts as cleared.

Letters in a grid can be chained horizontally or vertically (not diagonally), and each cell can be used at most once per word.

Implement:

  • exists(board, word): whether the word can be traced in the grid, using DFS with backtracking
  • find_words(board, words): the sorted list of distinct words from words that appear. Build a trie of the words and run a single DFS from each cell that follows the trie, so the cost doesn't grow with the number of words.

board is a list of equal-length strings.

#backtracking#dfs#tries2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Word Search in a Letter Grid · TechGradify