Loading...
Loading...
Loading...
A puzzle page shows a grid of capital letters. A word is in the grid if you can read it by starting at any cell and moving one cell up, down, left or right for each next letter, never using the same cell twice. Print YES if the word is in the grid and NO if it is not.
Example
Input
3 4 CATS OREP DENT CORE
Output
YES
C, O, R, E move down, right and right.
Try the problem first. Open one hint at a time.
Start a search from every cell whose letter matches the first letter of the word.
While you are inside a cell, overwrite it with # so it cannot be used again, and put the letter back when you leave.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor