Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
https://en.wikipedia.org/wiki/Minesweeper_(video_game)
Implement minesweep alogirthm
M*N
1000 * 1000 , 3 mines , mine position, you like to fill non-mines with numbers
time complexity and space complexity.
preprocessing all mines-> at most 8 neighbor has
k * 8 -> time complexity -> duplication here -> k worst case: m * n
for (int i=0; i < M; ++i){
for (int j=0; i < N; ++j){
if (arr[i][j] == '*'){
arr[i][j+1] = //
}
}
}
X 1 * 1 X
1 2 2 1 X
1 * 2 1 X
1 2 * 1 X
X 1 1 1 X
//M - row
//N - column
//K - no of mines
///
//? should we call it sweep
char[][] placeMines(int rows, int columns, int KMines){
}
// let say we need to fill matrix with large number of mines M*N-2 mines
//Approach:
int k =0;
Random rand = new Random();
while(k<Kmines)
{
int idx= rand.nextInt(rows *column);
if(grid[idx/M][idx%N]=='X)
{
grid[rowRandom][colRandom] = '*';
k++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.