Hard · Trie-style Backtracking
Understand → Visualise → Practice.
A grid path behaves like a trie search where each cell offers up to four next characters. Backtracking marks a cell during one path and restores it afterwards.
Start at matching first letters, advance one character per move, and never reuse a cell in the same path.
Reject out-of-bounds or wrong-character cells.
Temporarily make the cell unavailable.
Try four neighbours, then put the character back.
O(rows·cols·4ᴸ) worst-case time and O(L) recursion depth for word length L.
A global visited set is wrong; a cell may be reused by a different candidate path after backtracking.
Read the full guide first: Tries and Prefix Search.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.