← 返回 bytedance 的题目列表Minimum Time to Reach Bottom-Right in a Grid
类型:online_judge
Problem: Minimum Time to Reach Bottom-Right in a Grid (Minimize the Maximum Cell Value)
You are given an m x n integer grid grid, where grid[i][j] represents the required time threshold (or “height/time value”) associated with cell (i, j).
You start at the top-left cell (0, 0) and want to reach the bottom-right cell (m-1, n-1). From any cell, you may move to its 4-directional neighbors (up, down, left, right). Each move time is negligible.
Define the “required time” of a path as the maximum grid value among all cells on that path.
Return the minimum possible required time among all paths from (0, 0) to (m-1, n-1).
Input Format
First line: two integers m n
Next m lines: n integers describing grid
Output Format
Output one integer: the minimum required time.
Typical Constraints
1 <= m, n <= 200 (may vary)
0 <= grid[i][j] <= 1e9
Example
For grid = [[0,2],[1,3]], the answer is 3.
Note
Common solutions include: Dijkstra/priority queue (minimize the maximum along the path), binary search on the answer + reachability check, or Union-Find by activating cells in increasing order.
Example
Input
2 2
0 2
1 3
Output
3