LearnPy Hub
← Arena
IntermediateRating 1400

Find the Word in the Grid

Can the word be traced in the letter grid by moving up, down, left or right, using each cell at most once? Print YES or NO.

Input

r and c; r rows of letters; then the word.

Output

YES or NO.

Sample 1

Input
3 4
ABCE
SFCS
ADEE
ABCCED
Output
YES

Sample 2

Input
3 4
ABCE
SFCS
ADEE
SEE
Output
YES
solution.py
Output appears here
Find the Word in the Grid · Python Arena problem · LearnPy Hub