Skip to main content
Back to problems
Leetcode
Medium
Arrays
Matrices
Graphs
Google
Meta
Find Minimum Time To Reach Last Room I

Find the minimum time needed to travel from the first room to the last room in a grid of room times.

Acceptance 0%
Problem Statement

You are given a rectangular grid of rooms. You start in the top-left room and want to reach the bottom-right room.

Each room has an associated time value. Moving to an adjacent room takes 1 unit of time, and you can only enter a room once you have reached the required time for that room. Your task is to determine the minimum time needed to reach the last room.

If multiple routes are possible, choose the one with the smallest arrival time at the destination.

Input Format

  • A 2D grid of integers moveTime, where moveTime[r][c] represents the earliest time the room can be entered.
  • Start at (0, 0) and end at (m - 1, n - 1).
  • You may move up, down, left, or right to an adjacent room.

Output Format

  • Return a single integer: the minimum time needed to reach the bottom-right room from the top-left room.

Constraints

  • 1 <= m, n
  • Grid dimensions are small to moderate for interview-style pathfinding.
  • Times are non-negative integers.
  • You may assume the answer fits in a 32-bit signed integer.
Examples
Sample cases returned by the problem API.

Example 1

Input

moveTime = [[0,2,1],[1,3,4],[2,1,0]]

Output

4

Explanation

One optimal route is (0,0) -> (1,0) -> (2,0) -> (2,1) -> (2,2). The arrival time is governed by the movement cost of 1 per step and the room availability times, giving a minimum finish time of 4.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.