Find a word in a letter grid
You get a grid of letters board (a list of rows, each row a list of one-letter strings) and a string word. Return True if word can be spelled along a path on the board, and False otherwise.
A path starts on any cell and moves one cell at a time up, down, left or right, never diagonally. The cells along the path, in order, must hold the letters of word, and no cell may appear twice on one path. Two cells that hold the same letter are still two different cells.
Your function may change cells while it searches, but board must hold its original letters again when the function returns.
board = [["C", "A", "T"], ["O", "R", "E"], ["D", "E", "N"]], word = "CORE"OutputTrueStart on the C at the top left, step down to O, right to R, and right again to E.
board = [["C", "A", "T"], ["O", "R", "E"], ["D", "E", "N"]], word = "RARE"OutputFalseFrom the only R, step up to A. The only R next to that A is the one already on the path, and a cell cannot be used twice.
board = [["C", "A", "T"], ["O", "R", "E"], ["D", "E", "N"]], word = "ACORN"OutputFalseA, C, O and R join up, but the only N touches that R at a corner. Diagonal steps are not allowed.
1 ≤ number of rows, number of columns ≤ 6
1 ≤ len(word) ≤ 15
boardandwordhold only English letters.
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.