Minimum Time to Visit Cell in a Grid

Minimum Time to Visit Cell in a Grid

You are given an m x n matrix grid of non-negative integers. Each grid[row][col] represents the minimum time required to enter that cell. You start at (0, 0) at time t = 0. In each second, you can move to an adjacent cell (up, down, left, right). You can only enter a cell if the current time plus one second is greater than or equal to the value at that cell. If you cannot reach a cell at the required time, you may move back and forth between previously visited cells to wait. Return the minimum time to reach the bottom-right cell (m-1, n-1). If it is impossible, return -1. Constraints: m == grid.length, n == grid[i].length 2 <= m, n <= 1000 0 <= grid[i][j] <= 10^5 grid[0][0] == 0
JavaDijkstra's AlgorithmPriorityQueue
00
Read
1
InterviewGPT

AI-powered tools to help you succeed in tech interviews — from resume to offer.

Products

  • Interview Solver
  • Question Bank
  • Golden Blogs
  • Intervipedia
  • Application Tools

Company

  • Pricing
  • FAQ
  • About

Legal

  • Privacy Policy
  • Terms of Service

© 2026 InterviewGPT Inc. All rights reserved.

All systems operationalUS-East

Made with ♥ for developers