Ctrl K

Rooms Unlocked on Schedule

Medium
A building is an n × m grid of rooms. For each room you know opens[i][j], the moment (in seconds) from which you are allowed to **start moving into it** from a neighbouring room. You stand in room (0, 0) at time t = 0. In one move you can step into a room that shares a wall with yours (up, down, left or right), and a move takes exactly one second. You may wait in place as long as you like. Return the earliest moment you can be in room (n - 1, m - 1).
Example 1
opens=[[0, 3], [1, 9]] → 10

Head down to (1, 0) at time 1 and arrive at 2. The door to (1, 1) opens only at 9, so we arrive at 10. Going through (0, 1) is no better: we get there at 4 and still wait until 9.

Example 2
opens=[[0, 0, 0], [0, 0, 0], [0, 0, 0]] → 4

Every door is open from the start, so the time equals the shortest path: 4 steps.

Example 3
opens=[[0, 5, 0], [2, 7, 1]] → 8
Constraints
  • 2 ≤ n, m ≤ 100
  • 0 ≤ opens[i][j] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsShortest Path of a Rolling Ball MediumAcross the Hazard Field MediumRooms on Schedule, Limping Steps MediumBall Into the Hole HardRepaint Arrows to Reach the Exit Hard
loading Python…
Input
opens=[[0, 3], [1, 9]]
Expected
10

Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.