Latest Departure to Escape a Spreading Fire in a Data Hall
Last updated: November 29, 2026
Quick Overview
A technician starts at the top-left of a data hall grid with open floor (0), fire (1), and walls (2), and must reach the exit at the bottom-right. Each minute the technician moves one cell, then fire spreads to adjacent open cells; return the maximum minutes they can wait before leaving and still escape, -1 if impossible, or 10^9 if any wait works.
0
0
0 solved
A technician starts at the top-left of a data hall grid with open floor (0), fire (1), and walls (2), and must reach the exit at the bottom-right. Each minute the technician moves one cell, then fire spreads to adjacent open cells; return the maximum minutes they can wait before leaving and still escape, -1 if impossible, or 10^9 if any wait works.
A Google onsite question that layers two simulations: fire spreading over time and a person moving under a deadline. The interviewer checks multi-source BFS for fire arrival times, the precise arrival rule at the exit, and monotonicity that justifies binary search over the waiting time.
What the Interviewer Expects
- Compute fire arrival time per cell with multi-source BFS
- Define a feasibility check for a given wait using person BFS against fire times
- Apply the special rule: arriving at the exit at the same minute as fire is allowed, elsewhere it is not
- Show feasibility is monotone in the wait, then binary search
- Detect the never-burns case and return 10^9
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Can you solve it without binary search by comparing two BFS distance maps?
- What if fire spreads every two minutes?
- How would you also return the path the technician should take?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Grid m x n with 0, 1, 2. Start (0,0) and exit (m-1,n-1) are open. Per minute: the technician moves to an adjacent open cell (or the wait counts minutes standing still at the start), then f...
High-Level Design
Step 1: fire[c] = minute fire reaches cell c, by multi-source BFS from all fire cells through open cells (infinity if never).
Step 2: ok(w): the technician leaves at minute w, so require `w < fir...