Skip to content

Practice Minesweeper

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#529
LeetCode Problem

Minesweeper

Problem Statement

Update board after clicking one unrevealed cell. M denotes an unrevealed mine, E an unrevealed empty cell, B a revealed empty cell with no adjacent mines, digits 1 through 8 the number of adjacent mines, and X a revealed mine. Adjacency includes all eight surrounding positions. Clicking M changes it to X and ends the update. For an E cell, count adjacent mines: if the count is positive, replace E with that digit; otherwise replace it with B and reveal each adjacent unrevealed cell by the same rules. Stop when there are no further cells to reveal and return the updated board. The click array gives [row, column].

Source: Minesweeper on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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
[["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]

# Example 2

Input
board = [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]], click = [1,2]
Output
[["B","1","E","1","B"],["B","1","X","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]

Constraints

m == board.length
n == board[i].length
1 <= m, n <= 50
board[i][j] is either 'M', 'E', 'B', or a digit from '1' to '8'.
click.length == 2
0 <= clickr < m
0 <= clickc < n
board[clickr][clickc] is either 'M' or 'E'.

Related LeetCode Problems

Practice more problems similar to Minesweeper.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.