Reported March 2023
Airbytebreadth first search

Minesweeper Board Update

Reported by candidates from Airbyte's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Airbyte OA. Under 2s to a working solution.
Founder's read

Airbyte reportedly put Minesweeper Board Update in front of candidates in March 2023, and the whole thing hinges on one decision: how you traverse the grid. It's a flood fill on a matrix, either DFS with recursion or BFS with a queue. If you've got an OA invite and 48 hours, this is a good one to know cold, because the rules are simple and the bugs are all in the edges. Click a mine, mark X, done. Click empty, count eight neighbors, then either stamp a digit or stamp B and spread. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the pattern below should get you most of the way.

The problem

You are given a rectangular Minesweeper board containing unrevealed empty cells E and unrevealed mines M, plus a clicked coordinate [row, column].
If the clicked cell is a mine, change it to X and return the board.
Otherwise reveal the clicked empty region. For an unrevealed empty cell, count mines in all eight neighboring positions.
If the count is positive, replace the cell with the digit 1 through 8 and do not expand through it.
If the count is zero, replace the cell with B and continue revealing all adjacent unrevealed empty cells.
Mutate and return the board after the click.

Function
updateBoard(board: char[][], click: int[]) → char[][]

Examples
Example 1
board = [["E","E","E","E","E"],["E","E","M","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]]
click = [3,0]
return = [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]
The click opens a zero-mine region. Numbered boundary cells stop expansion, and the unrevealed cell behind the mine remains E.
Example 2
board = [["M","E"],["E","E"]]
click = [0,0]
return = [["X","E"],["E","E"]]
Clicking the mine marks only that cell as X.
Example 3
board = [["M","E"],["E","E"]]
click = [1,1]
return = [["M","E"],["E","1"]]
The clicked cell touches one mine, so it becomes 1 and expansion stops immediately.

Constraints
1 <= board.length, board[0].length <= 300
Every row has the same length.
Each board cell is E or M.
click contains a valid board coordinate.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that you only expand from cells with zero neighboring mines. For each popped cell, count mines among all eight neighbors first. If the count is positive, write the digit and stop. If it's zero, write B and push every neighbor that's still E. The common pitfall is marking cells too late. If you only mark on pop in BFS, the same cell enters the queue many times and you blow up runtime on a 300 by 300 board. Mark when you enqueue, or check for E at the top of the DFS call. Also, M neighbors count toward the number but never get revealed, and diagonals matter. Recursive DFS can hit stack depth on a large empty board, so BFS with a queue is safer. If the live OA scrambles your memory of this, StealthCoder is the hedge that reads the problem and hands you the traversal.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Minesweeper Board Update cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder
⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as minesweeper. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Airbyte's OA.

Airbyte reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minesweeper Board Update FAQ

What's the trick in Minesweeper Board Update?+

It's flood fill with a stop condition. Count the eight neighbors for the current cell. Positive count means write the digit and don't expand. Zero means write B and visit every unrevealed E neighbor. Handle the mine click as a separate early return that sets X.

Should I use DFS or BFS?+

Either is correct. BFS with a queue avoids recursion depth trouble on a 300 by 300 board full of empty cells. Recursive DFS is shorter to write but can overflow in some languages. Pick the one you can write without bugs in five minutes.

What's the most common bug?+

Revisiting cells. If you don't mark a cell as revealed when you enqueue it, duplicates pile up and you may time out or double-process. The second bug is forgetting diagonals, so your counts come out wrong on corner cases.

How hard is this really for an Airbyte OA?+

Medium. The logic is short, but the eight-direction loop, bounds checks, and mark-early discipline trip people up under time pressure. If you've done any grid flood fill like number of islands, you already know the skeleton.

How do I prepare in 48 hours?+

Write this once from scratch with a directions array of eight pairs and a helper that counts adjacent mines. Then test the three given examples by hand, especially the one where a mine click only changes that single cell. Don't read ten more problems, redo this one clean.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Airbyte.

OA at Airbyte?
Invisible during screen share
Get it