15% off all plans & roadmaps Use code
See plansLeetCode 212 · Solution & editorial
Given an m x n board of characters and a list of strings words, return all words on the board.
Word Search II is a Backtracking Patterns problem, in the Word Search / Path Finding in Grid subpattern. The pattern covers subsets, permutations, combinations, N-Queens, and word search
Search for words in grid using backtracking. Handle visited cells and path restoration.
The reference solution runs in O(M * 4^L + N) time and O(N + L) space.
Word Search II has been reported in interviews at Amazon, Microsoft, Uber, Apple, Google, Facebook, Snapchat, Twitter.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Word Search II is a Backtracking Patterns problem, in the Word Search / Path Finding in Grid subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.