Given a 2D array of mines, replace the question mark with the number of mines that immediately surround it. This includes the diagonals, meaning it is possible for it to be surrounded by 8 mines maximum.
The key is as follows:
- An empty space: "-"
- A mine: "#"
- Number showing number of mines surrounding it: "?"
minesweeper([
["-", "#", "-"],
["-", "?", "-"],
["-", "-", "-"]
]) ➞ [
["-", "#", "-"],
["-", "1", "-"],
["-", "-", "-"]
]
minesweeper([
["-", "#", "-"],
["#", "-", "?"],
["#", "#", "-"]
]) ➞ [
["-", "#", "-"],
["#", "-", "2"],
["#", "#", "-"]
]
minesweeper([
["-", "#", "#"],
["?", "#", ""],
["#", "?", "-"]
]) ➞ [
["-", "#", "#"],
["3", "#", ""],
["#", "2", "-"]
]
minesweeper([
["-", "-", "#"],
["?", "-", "-"],
["-", "-", "?"]
]) ➞ [
["-", "-", "#"],
["0", "-", "-"],
["-", "-", "0"]
]
- You will only be given square grids 3x3, 4x4 etc...
- The question mark is not limited to the centre.
- There may be multiple question marks.
std::vector<std::vector<char>> minesweeper(std::vector<std::vector<char>> grid){
}