Design a Minesweeper game. At game start, initialize an m×n board by randomly placing k bombs. Implement:
(
-
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).
(
-
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.