Find the minimum time needed to travel from the first room to the last room in a grid-like dungeon where each move has a time cost.
Problem
You are given a 2D grid of rooms. You start in the top-left room and want to reach the bottom-right room.
Each room may have a time value associated with it, and moving into a neighboring room can take different amounts of time depending on the destination room or movement rule. Your task is to compute the minimum total time required to reach the last room.
Treat the grid as a weighted graph where each cell is a node and valid moves are between adjacent cells. Return the minimum achievable time to reach the target room.
Notes
- You may move only in the allowed directions defined by the problem.
- If the destination cannot be reached, return the appropriate sentinel value for an unreachable state if specified by the platform formulation.
- This is a shortest-path problem on a grid with non-uniform edge costs.
Input Format
- A 2D grid describing the rooms or movement costs.
- The exact movement rules and cost function are determined by the grid values.
- Start is the first room; destination is the last room.
Output Format
- Return an integer representing the minimum time to reach the last room.
Constraints
- The grid is finite and rectangular.
- Costs are non-negative in the typical shortest-path formulation.
- A valid solution should handle large grids efficiently.
Example 1
Input
grid = [[0,1,2],[1,2,3],[2,3,4]]
Output
6
Explanation
One minimum-time route is to move along the top row and then down, accumulating the smallest reachable costs under the movement rule.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.