Loading
Loading
A puzzle magazine prints a rectangular grid of capital letters. A word is hidden in the grid if you can trace it by moving from a letter to a horizontally or vertically adjacent letter, one step per character, never using the same cell twice.
Each row of the grid is given as a string in grid. Return true if word can be traced, otherwise false.
grid = ["CAT", "ORE"], word = "CORE"(0,0) Cthe only C — start here(1,0) Odown(1,1) Rright(1,2) Eright — the whole word is tracedtrueSign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(cells · 3ᴸ) time · O(L) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
C (0,0) → O (1,0) → R (1,1) → E (1,2), each move to a side neighbour.
Example 2
The word needs a second B, but the grid has only one and a cell cannot be reused.