Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Minesweeper Implementation
00:00
5 left

Minesweeper Implementation

HardPython

Problem

Implement the Minesweeper game.

Given a 2D board and a clicked cell [row, col], return the updated board. M is an unrevealed mine, E is unrevealed empty space, B is revealed space with no adjacent mine, and digits show adjacent mine counts. If the click is a mine, change it to X. Otherwise, mark the clicked cell B, then reveal neighboring E cells: assign a digit when adjacent mines exist, or assign B and continue expanding when none exist. Existing revealed cells remain unchanged.

Signature: def update_board(board, click):

Examples: board=[['E','E'],['E','M']], click=[0,0] returns [['B','1'],['1','M']]. An empty board clicked at [0,0] reveals its connected region as B cells.

Constraints: the board is rectangular, non-empty, the click is valid, and there are at most 10,000 cells.

Constraints

  • 1 <= number of rows, number of columns
  • The board is rectangular and contains at most 10,000 cells
  • Each cell is one of E, M, B, or a digit from 1 to 8
  • click contains a valid row and column
  • The input board is mutated and returned

Function Signature

def update_board(board, click):
Interviewer

Your question is Minesweeper Implementation. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.