Back to questions

Word Search Apple Python Interview Question

Word Search

Apple Python Interview Question

Given an grid of characters and a string , return if exists in the grid.

For the word to exist, you must be able to construct it from a sequence of cells, where each is adjacent (horizontally or vertically, but not diagonal) to the next one in the sequence. The same cell may not be used twice.

Example #1

Word Search DataLemur Example

Input: board = [['A', 'L', 'E', 'D'], ['E', 'F', 'M', 'H'], ['I', 'R', 'U', 'L']] , word = "LEMUR"

Output: True

Example #2

Word Search Peter Example

Input: board = [['A', 'B', 'C', 'D'], ['P', 'E', 'T', 'H'], ['I', 'R', 'K', 'L']] , word = "PETER"

Output: False

Explanation: Cannot reuse the "E".

Example #3

Word Search Femur Example

Input: board = [['F', 'B', 'C', 'D'], ['E', 'M', 'G', 'H'], ['I', 'J', 'U', 'R']] , word = "FEMUR"

Output: False

Explanation: Cannot go diagonally from "M" to "U".

Input

Python

Output