Katkat

Design Minesweeper and Optimize Click Performance

BridgeSoftware Engineer · Technical Screen

Last updated

This question evaluates a candidate's competence in data structures, graph traversal and flood-fill concepts, complexity analysis, and scalable system design for sparse board representations.

Design a Minesweeper game. At game start, initialize an m×n board by randomly placing k bombs. Implement: (

  1. printBoard(): return a human-readable string of the current player-visible board (unrevealed cells remain hidden; revealed cells show 0–8; you may optionally support flags but keep the API clear). (
  2. click(r, c): if the cell is a bomb, mark game over; otherwise reveal the cell; if its adjacent-bomb count is zero, reveal the contiguous region per standard Minesweeper rules; handle repeated clicks, boundaries, and idempotency. Describe your data structures, key algorithms (e.g., BFS/DFS flood fill), and time/space complexity. Provide test cases. Follow-up: For very large, sparse boards (huge m, n with small k), propose and analyze optimizations to make click() fast and memory-efficient (e.g., lazy board generation, sparse data structures, on-demand neighbor counts, caching, or pruning), and discuss trade-offs.