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
- Use a queue or stack to avoid recursive depth limits.
- Mark a zero-adjacent cell B before adding neighbors.
- Numbered cells stop expansion.