Find a Word in a Letter Grid
Updated
Problem statement
You are given a board of letters as an array of strings board: board[i] is row i, and its j-th character is the letter in column j. You are also given a word.
Return true if the word can be spelled by a path on the board, and false otherwise. A path starts on any cell and, at each step, moves to a cell that shares a side with the current one (up, down, left or right; not diagonally). The letters along the path, in order, must be exactly the letters of word. A cell may be used at most once in the same path.
Function
wordInGrid(board: String[], word: String) → booleanExamples
Example 1
board = ["STEX","AONB","CKLM"]word = "STONE"return = trueStart at S in the top-left corner, step right to T, down to O, right to N and up to E. Each step goes to a side neighbour and no cell is used twice, so the answer is true.
Example 2
board = ["STEX","AONB","CKLM"]word = "NOTES"return = falseThe letters can be followed as far as E: N, left to O, up to T, right to E. But the only S is in the top-left corner, which does not touch that E, and there is no other N to start from. The answer is false.
Example 3
board = ["AB","CD"]word = "ABDCA"return = falseA, B, D, C go once around the square. The last A would have to be the top-left cell again, and a cell cannot be used twice, so the answer is false.
Constraints
1 <= board.length <= 61 <= board[i].length <= 6, and all rows have the same length1 <= word.length <= 15boardandwordcontain only uppercase English letters
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Enumerate Character Paths to a MarkerTesla · ONSITE INTERVIEWTesla interview questions
- Trace a Word Through a Letter GridExpedia · ONSITE INTERVIEWExpedia interview questions
- Word Search with Eight-Direction AdjacencyMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
- Count Islands with Eight-Direction AdjacencyAmazon · PHONE SCREEN
- Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
- Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
- Report Island Areas in Discovery OrderSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Word SearchCognitiv · PHONE SCREEN