Trains the technique from
LeetCode 529MinesweeperThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A construction site is surveyed square by square before anyone digs. board is the survey sheet, one character per square:
'M' a buried shell that the survey has located.'E' earth nobody has opened up yet.'B' earth already opened up with no shell in any square touching it.'1' through '8', earth already opened up, the digit being how many of the squares touching it hold a shell.Two squares touch when they share an edge or just a corner, so a square away from the border touches eight others.
The surveyor sinks one test pit at click = [click_r, click_c], and that square is always 'M' or 'E'. Work the sheet as follows:
'M', the shell is struck: write 'X' on that square and the survey stops there.'B' on the square and then open up every touching square that is still 'E' by these same rules, continuing outward from each square that turns out to be 'B'.Squares that already carry 'B' or a digit when the pit is sunk are left exactly as they are, are never opened up again, and the opening up never spreads outward from them. Modify board in place and return it.
Example 1
No shell touches the pit square, so it becomes `"B"` and the survey opens up the three squares touching it. Each of those has a shell somewhere among the squares it touches, so each takes a digit and the survey goes no further.
Example 2
The pit lands straight on a located shell, so that square is marked struck and nothing else on the sheet changes.
Example 3
The corner square touches the shell in the middle, so it takes the digit for one shell and the rest of the sheet is left alone.
Example 4
The middle square is surrounded on all eight sides by located shells, so it takes the digit for eight.
Example 5
The sheet holds no shells at all, so the pit square becomes `"B"` and the opening up carries on until every square on the sheet is `"B"`.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def update_board(board: list[list[str]], click: list[int]) -> list[list[str]]:public char[][] updateBoard(char[][] board, int[] click)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.