FastPrepCan Fit the Word
Problems/Can Fit the Word

Can Fit the Word

Google logoGoogle● MediumPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source illustrates empty cells with underscores but does not provide a rectangular encoded grid. The judged task uses _ as the empty marker and matches the visible source at about 96%.

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) → int

Examples

Example 1

grid = [['#', '#', '#', '#'], ['L', '_', '#', '#'], ['A', 'L', 'A', '_'], ['#', 'X', '#', '#']]word = "ALA"return = 0
grid
01230####1L_##2ALA_3#X##

The 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 = 1
grid
01230####1L_##2ALAN3#X##

The third row is one complete four-cell slot and exactly spells ALAN.

Constraints

  • grid is non-empty and rectangular.
  • Every grid cell is #, _, or an English letter.
  • word is 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

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int canFitTheWord(char[][] grid, String word) {
      // write your code here
    }

}
Checking account…