Quiz
#529 Minesweeper
APPROACH
You are playing Minesweeper. The m x n board uses these characters:
- 'M': unrevealed mine
- 'E': unrevealed empty cell
- 'B': revealed blank (no mines among its 8 neighbors)
- '1'–'8': revealed cell showing the adjacent mine count
- 'X': revealed mine
Given a click = [clickr, clickc] on an unrevealed cell, update and return the board using these rules:
- Clicking a mine 'M' ends the game; mark it 'X'.
- Clicking an empty cell 'E' with no adjacent mines marks it 'B' and recursively reveals all neighboring unrevealed cells.
- Clicking an empty cell 'E' with at least one adjacent mine marks it with the adjacent mine count digit.
- Stop when no further cells need revealing.
Example 1:
Example 2:
What is the optimal approach for this problem?