PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

Implement the reveal operation for a Minesweeper board. Correctly handle mine clicks, numbered cells, and recursive empty-region expansion across all eight neighbors while respecting board limits and avoiding repeated work.

  • medium
  • Nuro
  • Coding & Algorithms
  • Software Engineer

Reveal a Minesweeper Board

Company: Nuro

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Reveal a Minesweeper Board Implement the reveal operation for a Minesweeper game. The board contains unrevealed empty cells and mines. Given one click, update the board according to the normal reveal rules and return it. ### Function Signature ```python def reveal_board(board: list[list[str]], click: tuple[int, int]) -> list[list[str]]: ... ``` ### Cell Values - `"M"`: an unrevealed mine - `"E"`: an unrevealed empty cell - `"X"`: a revealed mine - `"B"`: a revealed empty cell with no adjacent mines - `"1"` through `"8"`: a revealed cell showing its adjacent-mine count Adjacent cells include all horizontal, vertical, and diagonal neighbors. ### Reveal Rules 1. If the clicked cell is a mine, replace it with `"X"` and stop. 2. Otherwise, count adjacent mines. 3. If the count is positive, replace the cell with that digit and stop expanding from it. 4. If the count is zero, replace the cell with `"B"` and reveal every adjacent unrevealed empty cell using the same rules. ### Constraints - `1 <= rows, columns` - `rows * columns <= 200_000` - `click` is inside the board and initially points to `"M"` or `"E"`. - The input board may be modified in place and returned. ### Example ```text Input board: E E E E E E E M E E E E E E E E E E E E Click: (3, 0) Output board: B 1 E 1 B B 1 M 1 B B 1 1 1 B B B B B B ``` ### Clarifications - Revealed cells are not expanded again. - Mine counts are based on `"M"` cells; the operation ends immediately when the clicked cell itself is a mine.

Quick Answer: Implement the reveal operation for a Minesweeper board. Correctly handle mine clicks, numbered cells, and recursive empty-region expansion across all eight neighbors while respecting board limits and avoiding repeated work.

Apply one standard Minesweeper reveal to a board. A clicked mine becomes X. A clicked empty cell becomes its adjacent-mine digit when positive; otherwise it becomes B and recursively reveals adjacent unrevealed empty cells.

Constraints

  • The board is nonempty and rectangular.
  • The click is in bounds and initially points to M or E.
  • All eight neighboring directions count for adjacent mines.
  • Only unrevealed E cells expand.
  • The board may be modified in place and returned.

Examples

Input: ([["M"]], (0, 0))

Expected Output: [["X"]]

Explanation: Clicking a mine reveals X and stops.

Input: ([["E"]], (0, 0))

Expected Output: [["B"]]

Explanation: An isolated empty cell has zero adjacent mines.

Hints

  1. Use a queue or stack to avoid recursive depth limits.
  2. Mark a zero-adjacent cell B before adding neighbors.
  3. Numbered cells stop expansion.
Last updated: Jul 15, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Generate Weighted Random Keys With Add And Remove - Nuro (medium)
  • Find Intersections Between Two Interval Lists - Nuro (medium)
  • Map Weighted Random Draws to Indices - Nuro (medium)
  • Parse logs and count error codes - Nuro (easy)