Word Search in Grid
Hardjavapythonccppjavascript
Given a grid of letters and a target word, determine whether the word can be formed by a path of adjacent cells (up, down, left or right). The same cell may not be used more than once in a single path.
Input Format
The first line contains two integers R and C. Each of the next R lines contains C characters (uppercase letters, no spaces). The last line contains the target word.
Output Format
Print 1 if the word can be formed, otherwise print 0.
Example 1
Input
3 4 ABCE SFCS ADEE ABCCED
Output
1
Explanation: The word can be traced through adjacent cells without reusing a cell.
- 1 <= R, C <= 15
- 1 <= word length <= 15
- Letters are uppercase English letters.