#3342

Find Minimum Time to Reach Last Room II

specialist · 605 · lc medium +29 · 67.9% accepted · 357 likes · top 74%

Description

A dungeon consists of n x m rooms arranged in a grid.

You are given a 2D array moveTime of size n x m, where moveTime[i][j] is the earliest time (in seconds) when you may begin moving to room (i, j). You start at room (0, 0) at time t = 0. Moves to adjacent rooms alternate in cost: one second for the first move, two seconds for the next, and so on.

Return the minimum time required to reach room (n - 1, m - 1).

Two rooms are adjacent if they share a wall horizontally or vertically.

Code

1
2
3