Hi! The outputs are just placeholders. This problem is here to give you a glimpse of what a Google interviewer asked in one of their phone screens today. And today is 03-27-2025
We are given a grid of size N*M having characters "#", "" (empty space), and any English lowercase alphabet letter.
"#": Filled"": Empty- Any English alphabet letter
We are also given a string word. We have to find if we can fit this word in the grid either by directly matching with English alphabet letters or using the empty spaces (by filling them with matching characters). The word should match exactly, and no empty space should be left before and after. We can have the word match from left to right and top to bottom only.
grid = [['#', '#', '#', '#'], ['L', '_', '#', ' '], ['A', 'L', 'A', '_'], ['#', 'X', '#', '_']] word = "ALA" return = 0
The word ALA does not fit as we have one space left at the end.
#### ####
L_# ALA_#
#X#__ #X#__
grid = [['#', '#', '#', '#'], ['L', '_', '#', ' '], ['A', 'L', 'A', 'N'], ['#', 'X', '#', '_']] word = "ALAN" return = 1
The word ALAN fits.
#### ####
L_# ALAN#
#X#__ #X#__
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
- Minimum Cars for Rental RequestsONSITE INTERVIEW · Seen Apr 2026
- Shortest Path with Mandatory WaypointONSITE INTERVIEW · Seen Apr 2026
- Count Divisible Coin SelectionsOA · Seen Dec 2025
public int canFitTheWord(char[][] grid, String word) {
// write your code here
}