Word Search
Updated
Problem statement
Given a rectangular character grid board and a string word, return true if word can be formed by a path through the grid. Otherwise, return false.
A path may move horizontally or vertically between adjacent cells. The same grid cell cannot be used more than once in one path.
Function
wordExists(board: char[][], word: String) → booleanExamples
Example 1
board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]word = "ABCCED"return = trueThe path uses the top-row cells A, B, and C, then continues down to C, left to E, and left to D.
Example 2
board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]word = "ABCB"return = falseThe only adjacent B that could finish the word is the cell already used after the starting A, and a cell cannot be reused.
Example 3
board = [["A"]]word = "A"return = trueThe single grid cell forms the complete word.
Constraints
1 <= board.length <= 61 <= board[i].length <= 6- Every row of
boardhas the same length. 1 <= word.length <= 15boardandwordcontain only uppercase and lowercase English letters.
More Microsoft Onsite Interview questions
- 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
- Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Word SearchAmazon · ONSITE INTERVIEW
- 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 GridMeta · ONSITE INTERVIEWMeta interview questions
- Enumerate Top-to-Bottom Grid PathsGoogle · ONSITE INTERVIEWGoogle interview questions
- Word SearchCognitiv · PHONE SCREEN
- Find a Word in a Letter GridAdobe · PHONE SCREENAdobe interview questions
- Word SearchWhatNot · PHONE SCREENWhatNot interview questions
- Rat in a Maze: All Simple PathsPeopleStrong · OAPeopleStrong interview questions
Interview reports that mention this question
Microsoft interview experiences
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
- Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)