Find Minimum Time to Reach Last Room I

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.

Example 1
InputmoveTime = [[0,4],[4,4]]
Output6
The minimum time required is 6 seconds: move from room (0, 0) to room (1, 0) at t == 4, then from room (1, 0) to room (1, 1) at t == 5.
Example 2
InputmoveTime = [[0,0,0],[0,0,0]]
Output3
The minimum time required is 3 seconds by moving from (0, 0) to (1, 0), then to (1, 1), then to (1, 2).

Constraints

  • 2 <= n == moveTime.length <= 50
  • 2 <= m == moveTime[i].length <= 50
  • 0 <= moveTime[i][j] <= 10^9

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate