Implement BFS and a Job Scheduler
Company: Nuro
Role: Backend Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
The interview report described two coding questions in the same category:
1. **Grid reveal with BFS**
You are given an `m x n` board representing a hidden minefield. Each cell is one of:
- `M`: unrevealed mine
- `E`: unrevealed empty cell
- `B`: revealed blank cell with no adjacent mines
- `1`-`8`: revealed cell showing the number of adjacent mines
- `X`: revealed mine after a click
Given a click position `(row, col)`, update the board using these rules:
- If the clicked cell is a mine (`M`), change it to `X`.
- Otherwise, reveal cells using **BFS**:
- Count the number of mines in the 8 neighboring cells.
- If the count is greater than 0, write that digit in the cell and stop expanding from it.
- If the count is 0, mark the cell as `B` and continue revealing its unrevealed neighbors.
Return the updated board.
2. **Concurrent periodic job scheduler**
Implement a thread-safe in-memory scheduler that supports periodic jobs.
Each job has:
- a unique `jobId`
- an execution interval such as every `N` milliseconds
- a callback function to run
Support the following operations:
- `register(jobId, intervalMs, task)`
- `cancel(jobId)`
- `start()`
- `stop()`
Requirements:
- Multiple worker threads may execute jobs concurrently.
- A job should be triggered approximately once per interval.
- The same scheduled run must not execute more than once.
- Cancellation must be safe even if other threads are polling or executing jobs.
- Explain how you would handle cases where a task runs longer than its interval, clock drift, and backpressure under heavy load.
Quick Answer: This question evaluates algorithmic problem-solving and concurrency engineering skills by combining a BFS-based grid-reveal algorithm for minefield traversal and a thread-safe periodic job scheduler requiring synchronization and scheduling semantics.