Skip to content

Practice Find Minimum Time to Reach Last Room II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3342
LeetCode Problem

Find Minimum Time to Reach Last Room II

Problem Statement

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 when you can start moving to that room. You start from the room (0, 0) at time t = 0 and can move to an adjacent room. Moving between adjacent rooms takes one second for one move and two seconds for the next, alternating between the two. 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.

Source: Find Minimum Time to Reach Last Room II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
moveTime = [[0,4],[4,4]]
Output
7

# Example 2

Input
moveTime = [[0,0,0,0],[0,0,0,0]]
Output
6

# Example 3

Input
moveTime = [[0,1],[1,2]]
Output
4

Constraints

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

Related LeetCode Problems

Practice more problems similar to Find Minimum Time to Reach Last Room II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.