Created
August 6, 2021 12:52
-
-
Save CoGrammarCodeReview/ad478fd583270fd162d3e7125d69f3c0 to your computer and use it in GitHub Desktop.
Minesweeper Challenge for Mock Interviews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This challenge is based on the game Minesweeper. | |
Create a function that takes a grid of # and -, | |
where each hash (#) represents a mine and each dash | |
(-) represents a mine-free spot. Return an array where | |
each dash is replaced by a digit indicating the number | |
of mines immediately adjacent to the spot | |
(horizontally, vertically, and diagonally). | |
Examples | |
numGrid([ | |
["-", "-", "-", "-", "-"], | |
["-", "-", "-", "-", "-"], | |
["-", "-", "#", "-", "-"], | |
["-", "-", "-", "-", "-"], | |
["-", "-", "-", "-", "-"] | |
]) ➞ [ | |
["0", "0", "0", "0", "0"], | |
["0", "1", "1", "1", "0"], | |
["0", "1", "#", "1", "0"], | |
["0", "1", "1", "1", "0"], | |
["0", "0", "0", "0", "0"], | |
] | |
numGrid([ | |
["-", "-", "-", "-", "#"], | |
["-", "-", "-", "-", "-"], | |
["-", "-", "#", "-", "-"], | |
["-", "-", "-", "-", "-"], | |
["#", "-", "-", "-", "-"] | |
]) ➞ [ | |
["0", "0", "0", "1", "#"], | |
["0", "1", "1", "2", "1"], | |
["0", "1", "#", "1", "0"], | |
["1", "2", "1", "1", "0"], | |
["#", "1", "0", "0", "0"] | |
] | |
numGrid([ | |
["-", "-", "-", "#", "#"], | |
["-", "#", "-", "-", "-"], | |
["-", "-", "#", "-", "-"], | |
["-", "#", "#", "-", "-"], | |
["-", "-", "-", "-", "-"] | |
]) ➞ [ | |
["1", "1", "2", "#", "#"], | |
["1", "#", "3", "3", "2"], | |
["2", "4", "#", "2", "0"], | |
["1", "#", "#", "2", "0"], | |
["1", "2", "2", "1", "0"], | |
] | |
Source: https://edabit.com/challenge/voZCqTGMSNjCrRhf9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment