All problems
Minesweeper Reveal
Problem
Given a minesweeper board of E, M and digit characters, reveal the cell at click and return the new board.
Clicking a mine turns it into X. Clicking an empty cell with no adjacent mines reveals it as B and recursively reveals its neighbours, while an empty cell adjacent to mines shows the count. Do not modify the input board.
Hint
Mark neighbours as B when enqueueing so they are not queued twice.
Test cases
case 1
in: [[["E","E","E","E","E"],["E","E","M","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]],[3,0]]
expected: [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]
case 2
in: [[["E","E","E","E","E"],["E","E","M","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]],[1,2]]
expected: [["E","E","E","E","E"],["E","E","X","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]]
case 3
in: [[["M"]],[0,0]]
expected: [["X"]]
case 4
in: [[["E"]],[0,0]]
expected: [["B"]]
case 5
in: [[["E","E","E"],["E","M","E"],["E","E","E"]],[0,0]]
expected: [["1","E","E"],["E","M","E"],["E","E","E"]]
Starter codePython
def minesweeper_reveal(board, click):
# Your code here
pass5 test cases · run your code against them in the editor