Can Fit the Word
Updated
Problem statement
You are given a rectangular character grid containing blocked cells #, empty cells _, and English letters, plus a string word.
A slot is a maximal contiguous run of non-blocked cells in one row or one column. The word fits when a slot has exactly the same length as the word and, reading left-to-right or top-to-bottom, every slot cell is either _ or already equals the corresponding word character. Empty cells may be filled with the required letters.
Return 1 if the word fits in at least one slot; otherwise return 0.
Function
canFitTheWord(grid: char[][], word: String) → intExamples
Example 1
grid = [['#', '#', '#', '#'], ['L', '_', '#', '#'], ['A', 'L', 'A', '_'], ['#', 'X', '#', '#']]word = "ALA"return = 0The row containing ALA_ is a four-cell slot, so placing the three-letter word would leave one empty cell. No vertical slot matches.
Example 2
grid = [['#', '#', '#', '#'], ['L', '_', '#', '#'], ['A', 'L', 'A', 'N'], ['#', 'X', '#', '#']]word = "ALAN"return = 1The third row is one complete four-cell slot and exactly spells ALAN.
Constraints
gridis non-empty and rectangular.- Every grid cell is
#,_, or an English letter. wordis non-empty and contains English letters.
More Google Phone Screen questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Straight-Line Word SearchReddit · PHONE SCREENReddit interview questions
- Excel Training Data and Model Response AuditMicrosoft · PHONE SCREENMicrosoft interview questions
- Implement Explicit Integer EinsumNVIDIA · PHONE SCREENNVIDIA interview questions
- Transpose a String GridIndeed · PHONE SCREENIndeed interview questions
- Repair One Movement InstructionOpenAI · OAOpenAI interview questions
- Count Straight-Line Word Occurrences in a GridOptiver · OAOptiver interview questions
- Cyclic Fuel Command SimulationWaymo · ONSITE INTERVIEWWaymo interview questions
- BitFont Part 2 - Render a WordStripe · ONSITE INTERVIEWStripe interview questions
- Count Straight-Line Word Occurrences in a GridVisa · OAVisa interview questions
- Count Grid Words with One TurnCapital One · OACapital One interview questions