Reveal a Minesweeper Region
Updated
Problem statement
You are given a rectangular Minesweeper board. A mine is encoded as -1, and every unrevealed empty cell is encoded as 0.
Reveal the region that begins at the empty cell (startRow, startCol). Two cells are adjacent when their row and column differ by at most one, excluding the cell itself.
When an unrevealed empty cell is reached:
- Count the mines among its at most eight adjacent cells.
- If the count is positive, replace the cell with that count and do not expand from it.
- If the count is zero, replace the cell with
-2, then continue the reveal from each adjacent cell that is still0.
Mines remain -1, and empty cells that are never reached remain 0. Return the resulting board.
Function
revealRegion(board: int[][], startRow: int, startCol: int) → int[][]Examples
Example 1
board = [[0,0,0,0,0],[0,0,0,-1,0],[0,0,0,0,0],[0,0,0,0,0]]startRow = 3startCol = 0return = [[-2,-2,1,0,0],[-2,-2,1,-1,0],[-2,-2,1,1,1],[-2,-2,-2,-2,-2]]The reveal begins in the mine-free lower-left region. Every zero-clue cell in that region becomes -2, and its numbered boundary is revealed. Expansion stops at those numbered cells, so the two empty cells beyond the mine remain 0.
Example 2
board = [[0,0,0],[0,0,0]]startRow = 0startCol = 1return = [[-2,-2,-2],[-2,-2,-2]]The board contains no mines. Every empty cell is connected to the reveal origin and has zero adjacent mines, so every cell becomes -2.
Example 3
board = [[0,-1,0],[0,0,0],[0,0,-1]]startRow = 1startCol = 1return = [[0,-1,0],[0,2,0],[0,0,-1]]The origin has two adjacent mines, so it is revealed as 2. Because its clue is positive, the reveal does not expand to any neighbor.
Constraints
1 <= board.length <= 200.1 <= board[r].length <= 200, and every row has the same length.- Every initial cell is
-1or0. 0 <= startRow < board.lengthand0 <= startCol < board[0].length.board[startRow][startCol] == 0.
More Nuro interview questions
- Merge Timestamped Record ListsPHONE SCREEN · Seen Oct 2026
- Assign Robots to Their Nearest Available ItemsPHONE SCREEN · Seen Oct 2026
- Container With Most WaterPHONE SCREEN · Seen Oct 2026
- Course Ordering with Concurrent UpdatesPHONE SCREEN · Seen Sep 2026
- Group Sparse Points by Distance ThresholdPHONE SCREEN · Seen Sep 2026
- Schedule Buffered Video PlaybackPHONE SCREEN · Seen Aug 2026
- Maximum Value for Two Delivery RobotsPHONE SCREEN · Seen Jul 2026
- Thread-Safe Task Storage and Worker DispatchONSITE INTERVIEW · Seen Sep 2026
- Trapping Rain WaterONSITE INTERVIEW · Seen Sep 2026
- Versioned Key-Value Store with Suffix TruncationONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Count Battleships by SizeDeloitte · OADeloitte interview questions
- Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Grid Infection with Recovery After D DaysOpenAI · PHONE SCREENOpenAI interview questions
- Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
- Count Groups of Diseased PlantsYellow.ai · PHONE SCREEN
- Days Until Poisoned Plants StabilizeApple · PHONE SCREENApple interview questions
- Apply a 2048 Board MoveGlean · PHONE SCREENGlean interview questions
- File-Backed Dense Game of LifeApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Count Enclosed Freshwater RegionsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions