The Find Minimum Time to Reach Last Room II interview question is an evolution of the grid-waiting problem. In this version, the time it takes to move between rooms is no longer always 1 second. Instead, it alternates: your first move takes 1 second, your second move takes 2 seconds, your third takes 1 second, and so on. The "waiting for room to open" logic remains the same.
Google and Uber ask this variation to see if you can incorporate "Path History" or "Move Count" into your shortest path calculation. It evaluates your ability to define a Multi-dimensional State in Dijkstra's algorithm. It checks if you understand that the "cost" to reach a node now depends on how many steps you've taken to get there.
This follows the Dijkstra's Algorithm pattern with an Expanded State.
(time, row, col, moveType), where moveType is 0 or 1 (representing 1-second or 2-second moves).moveType is 0, the next move takes 1 second. The neighbor will have moveType 1.moveType is 1, the next move takes 2 seconds. The neighbor will have moveType 0.newTime = max(currentTime, grid[nr][nc]) + (1 if moveType == 0 else 2).Grid: [[0, 1], [1, 1]]. Start (0,0) at , move parity 0.
minTime[r][c]. Since the time to reach a cell depends on the move parity, you might need minTime[r][c][parity]. (Wait, actually, in this specific problem, reaching a cell with fewer steps is always better regardless of parity, but be careful with this assumption).(row + col) % 2 to determine move cost. This only works if you don't revisit cells; tracking it in the state is safer.When a rule changes based on "how many times" an action has been performed, always add that count (or its parity) to your BFS/Dijkstra state. This is a foundational technique for "Hard" Graph interview patterns.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Minimum Time to Reach Last Room I | Medium | Solve | |
| Find a Safe Walk Through a Grid | Medium | Solve | |
| Path with Maximum Probability | Medium | Solve | |
| Minimum Obstacle Removal to Reach Corner | Hard | Solve | |
| Minimum Time to Visit a Cell In a Grid | Hard | Solve |