Back to DSA

Word Search II

hard
Acceptance: 37%
TrieBacktrackingMatrix

Given a two-dimensional grid of characters and a list of target words, find every word from the list that can be formed by tracing a path of horizontally or vertically adjacent cells on the grid. Each cell may be used at most once per word.

Examples

Example 1:
Input:board = [['p','q','r','s'],['t','u','v','w'],['x','y','z','a'],['b','c','d','e']], words = ['puy','quz','xyz','pqr']
Output:['pqr','xyz']

Hints

00:00
1234567