Word Search
Updated
Problem statement
Given a rectangular character grid represented by the strings in board and a nonempty word, return true if the word can be formed by following a path through the grid.
- The path may start at any cell.
- Each next cell must be immediately above, below, left, or right of the previous cell. Diagonal moves are not allowed.
- A cell may be used at most once in the same path.
- The characters along the path must match
wordin order.
Function
wordSearch(board: String[], word: String) → booleanExamples
Example 1
board = ["ABCE","SFCS","ADEE"]word = "ABCCED"return = trueA path starts at the top-left cell, moves right twice, down twice, then left to spell the word.
Example 2
board = ["ABCE","SFCS","ADEE"]word = "SEE"return = trueStart at the S in the rightmost column, move down to E, then left to E.
Example 3
board = ["ABCE","SFCS","ADEE"]word = "ABCB"return = falseSpelling the final B would require using the same top-row B cell twice.
Constraints
1 <= board.length <= 10.- All rows have the same length
c, with1 <= c <= 10andboard.length * c <= 50. - Grid cells and the word contain only uppercase English letters.
1 <= word.length <= 10.
More WhatNot Phone Screen questions
- Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 2026
- Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
- Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
- Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
- Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
- Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Word SearchCognitiv · PHONE SCREEN
- Find a Word in a Letter GridAdobe · PHONE SCREENAdobe interview questions
- Adjacent-Key Lock PatternsC3.ai · PHONE SCREENC3.ai interview questions
- Word Search IIApple · PHONE SCREENApple interview questions
- Word SearchAmazon · ONSITE INTERVIEW
- Word SearchMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Enumerate Character Paths to a MarkerTesla · ONSITE INTERVIEWTesla interview questions
- Trace a Word Through a Letter GridExpedia · ONSITE INTERVIEWExpedia interview questions
- Rat in a Maze: All Simple PathsPeopleStrong · OAPeopleStrong interview questions