Find Minimum Time to Reach Last Room I - Problem
There is a dungeon with n x m rooms arranged as a grid. You are given a 2D array moveTime of size n x m, where moveTime[i][j] represents the minimum time in seconds after which the room opens and can be moved to.
You start from the room (0, 0) at time t = 0 and can move to an adjacent room. Moving between adjacent rooms takes exactly one second.
Return the minimum time to reach the room (n - 1, m - 1).
Two rooms are adjacent if they share a common wall, either horizontally or vertically.
Input & Output
Example 1 — Basic Grid
$
Input:
moveTime = [[0,1,1],[1,1,1]]
›
Output:
3
💡 Note:
Start at (0,0) at time 0 → move to (0,1) at time 1 → move to (1,1) at time 3 (wait until room opens). Total time: 3 seconds.
Example 2 — Blocked Path
$
Input:
moveTime = [[0,2,99],[1,1,1]]
›
Output:
5
💡 Note:
Path: (0,0) t=0 → (1,0) t=1 → (1,1) t=2 → (0,1) t=3 (wait) → (1,1) t=5. Need to alternate to reach time 2 for (0,1).
Example 3 — Simple Path
$
Input:
moveTime = [[0,1],[2,3]]
›
Output:
3
💡 Note:
Direct path: (0,0) t=0 → (0,1) t=1 → (1,1) t=3 (wait for room to open at time 3). Total: 3 seconds.
Constraints
- 2 ≤ n, m ≤ 750
- n == moveTime.length
- m == moveTime[i].length
- 0 ≤ moveTime[i][j] ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input Grid
2D array where each cell has minimum opening time
2
Path Finding
Find shortest time path considering wait periods
3
Output Time
Minimum time to reach bottom-right corner
Key Takeaway
🎯 Key Insight: Use Dijkstra's algorithm to handle time constraints and waiting periods efficiently
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code