Choose the Next Minesweeper Action
Updated
Problem statement
Choose one next action for a Minesweeper bot from the currently visible board. A revealed number tells you how many mines are in its neighboring cells. There are at most eight neighbors, including diagonals. Do not include the numbered cell itself.
For this bounded practice exercise, board[r][c] is -1 for an unknown cell, -2 for an already flagged known mine, or a number from 0 through 8 for a revealed safe cell. Flags are assumed correct. Hidden mine locations are not supplied.
Explicit probability model
Start by treating every way to mark the unknown cells as mines or safe as equally likely. Keep only the assignments that agree with every visible number and existing flag. Each remaining assignment is equally likely. You are not given the total number of mines. At least one assignment is guaranteed to match the board.
One-step action contract
- If no unknown cell remains, return
[2, -1, -1]forDONE. - If any unknown cell is a mine in every consistent assignment, return
[1, row, col]forFLAG, choosing the first such cell in row-major order. - Otherwise return
[0, row, col]forREVEALat the unknown cell with the lowest mine probability across all consistent assignments. Break ties by row-major order.
Coordinates are zero-based. Return only the action; do not change the board or simulate a reveal. Minimum immediate reveal risk under this model does not claim a globally optimal strategy for winning a complete game.
Function
nextMinesweeperAction(board: int[][]) → int[]Examples
Example 1
board = [[0,-1],[-1,-1]]return = [0,0,1]All three unknown neighbors are safe in every consistent assignment; reveal the first in row-major order.
Example 2
board = [[1,-1]]return = [1,0,1]The single unknown neighbor must be a mine; return FLAG at row 0 column 1.
Example 3
board = [[-1,-1]]return = [0,0,0]Both unknown cells have mine probability one-half under the explicit prior; reveal row 0 column 0 by the tie rule.
Constraints
- The rectangular board has from
1through4rows and columns. - There are at most
15unknown cells. - Every entry is
-2,-1, or an integer from0through8. - Every revealed number is consistent with at least one assignment to all unknown cells, treating existing flags as mines.
- Use all visible clues together; assignments outside the board do not exist.
More Runloop Phone Screen questions
Similar questions at other companies
- Maximum Words in Disjoint Grid PathsIndeed · PHONE SCREENIndeed interview questions
- Boggle GameAirbnb · PHONE SCREENAirbnb interview questions
- Count Eight-Neighbor Unlock PatternsGoogle · ONSITE INTERVIEWGoogle interview questions
- Knights, Knaves and Their StatementsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Prefix Matrix Products and AutogradOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Sudoku Puzzle SolverConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Visit Desired Attractions Without Reusing a TrailDuolingo · PHONE SCREENDuolingo interview questions
- Best-Fit Plane Normal from 3D PointsThe Voleon Group · PHONE SCREEN
- Maximum Currency Conversion Along a Simple PathRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Town Temperature Regression AnalysisCitadel · PHONE SCREENCitadel interview questions