Reveal a Minesweeper Board After the Player Clicks One Cell

Last updated: November 29, 2026

Quick Overview

Given a Minesweeper board of unrevealed mines 'M', unrevealed empty cells 'E', and already revealed cells, plus a click position, return the board after applying the click: a mine becomes 'X', an empty cell shows its adjacent mine count, and a zero cell reveals its neighbors recursively.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given a Minesweeper board of unrevealed mines 'M', unrevealed empty cells 'E', and already revealed cells, plus a click position, return the board after applying the click: a mine becomes 'X', an empty cell shows its adjacent mine count, and a zero cell reveals its neighbors recursively.

A Google onsite simulation problem in the spirit of the Minesweeper game that shipped with search doodles. The interviewer checks that you translate the game rules exactly, use BFS or DFS with a visited guard, and do not expand past numbered cells.

What the Interviewer Expects
  • Handles the mine click as an immediate terminal case
  • Counts mines among all 8 neighbors
  • Reveals a number and stops when the count is positive
  • Expands to neighbors only from blank cells
  • Marks cells as revealed when enqueued to avoid duplicates
Key Topics to Cover
BFS
Simulation
8-Directional Neighbors
Grid State Machines
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Guarantee the first click is never a mine by regenerating the board lazily.
  • Implement a 'chord' click that reveals neighbors when flags match the number.
  • Board is 10,000 x 10,000; is recursion safe and what about memory?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • board: list of lists of chars 'M', 'E', 'B' (revealed blank), '1'..'8', 'X'.
  • click: (r, c) on an 'M' or 'E' cell.
  • Rules: 'M' becomes 'X' and the game ends. 'E' with k >...
High-Level Design

Mines are never revealed by expansion because a blank has zero mine neighbors by definition. So the expansion only ever touches 'E' cells. Use an iterative BFS: when popping a cell, count adjacent `...


Submit Your Answer
Markdown supported