Word Search with Eight-Direction Adjacency
Updated
Problem statement
Given a square character grid board and a nonempty string word, return true if the word can be formed by a path through the grid.
From each cell, the path may move to any of its eight horizontal, vertical, or diagonal neighbors. A path may change direction between characters, but it cannot use the same cell more than once.
Function
wordExists8Directions(board: char[][], word: String) → booleanExamples
Example 1
board = [["A","B"],["C","D"]]word = "AD"return = trueThe path moves diagonally from the upper-left A to the lower-right D.
Example 2
board = [["A","B"],["C","D"]]word = "ABA"return = falseThe only A would need to be reused after visiting B, which is forbidden.
Constraints
1 <= board.length <= 6board[i].length = board.length1 <= word.length <= board.length * board.length- The grid and word contain uppercase and lowercase English letters, matched case-sensitively.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 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
- Find a Word in a Letter GridAdobe · PHONE SCREENAdobe interview questions
- Number of IslandsFleetx · ONSITE INTERVIEW
- Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
- Word SearchAmazon · ONSITE INTERVIEW
- Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
- Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
- Query Whether an Island Size ExistsMeta · ONSITE INTERVIEWMeta interview questions